I'm trying to run Clover to see test coverage, but it will not create any database (and thus not give any report).
Among others, I've tried to run
mvn clean clover2:setup clover2:instrument clover2:clover clover2:check
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<version>4.0.4</version>
<configuration>
<!-- <cloverDatabase>C:\clover\clover.db</cloverDatabase> -->
<!-- <reportsDirectory>${project.build.directory}/testreports</reportsDirectory> -->
<targetPercentage>10%</targetPercentage>
<includes>
<include>**Test.java</include>
<include>**IT.java</include>
</includes>
</configuration>
<executions>
<execution>
<id>verify</id>
<phase>verify</phase>
<goals>
<goal>instrument</goal>
<goal>check</goal>
<goal>setup</goal>
</goals>
</execution>
</executions>
</plugin>
I've run with and without the <cloverDatabase> and <reportsDirectory> properties. No difference.
No database is ever created anywhere. Why?
I managed to get it working again by removing Clover, and then adding Clover back with only simple settings
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<version>4.0.4</version>
<configuration>
<targetPercentage>70%</targetPercentage>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>instrument</goal>
</goals>
</execution>
</executions>
</plugin>
If I try to add inclusion specifications, then suddenly it won't create any db anymore....
Related
I am trying to run a mvn exec for one of my spring boot apps but it is giving me a class loader exception.
I have an app in main named App.java that runs of 28433 port.
I also have an app in src/test named MockServerApp.java.
I am trying to run mvn exec to execute them.
When I do mvn exec on my main app it works and starts. When I do it on my MockServerApp though it causes a class loader exception.
Here is my POM
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>default-cli</id>
<configuration>
<mainClass>com.nulogix.billing.App</mainClass>
</configuration>
</execution>
<execution>
<id>second-cli</id>
<configuration>
<mainClass>com.nulogix.billing.mockserver.MockServerApp</mainClass>
</configuration>
</execution>
</executions>
</plugin>
Here is the error I am getting :
java.lang.ClassNotFoundException: com.nulogix.billing.mockserver.MockServerApp
at java.net.URLClassLoader.findClass (URLClassLoader.java:436)
at java.lang.ClassLoader.loadClass (ClassLoader.java:588)
at java.lang.ClassLoader.loadClass (ClassLoader.java:521)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:270)
at java.lang.Thread.run (Thread.java:835)
How do I fix this?
EDIT: I have tried using the spring-boot-maven-plugin since I will be using the MockAppServer for integration tests and have tried launching both in the pre-integration life cycle.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.nulogix.billing.App</mainClass>
</configuration>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>pre-integration-test2</id>
<goals>
<goal>start</goal>
</goals>
<configuration>
<mainClass>com.nulogix.billing.mockserver.MockServerApp</mainClass>
</configuration>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
<configuration>
<mainClass>com.nulogix.billing.App</mainClass>
</configuration>
</execution>
<execution>
<id>post-integration-test2</id>
<goals>
<goal>stop</goal>
</goals>
<configuration>
<mainClass>com.nulogix.billing.mockserver.MockServerApp</mainClass>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
Still gives me the classNotFoundException.
You can mark MockServerApp with following annotations. And instead of trying to run MockServerApp from maven, you can simply run junits from maven and let Spring manage creation of test context.
#RunWith(SpringRunner.class)
#SpringBootTest
You can see further documentation at spring boot testing
We are moving our existing project from Ant + Eclipse to Maven + IntelliJ IDEA.
I am currently using JAXB to generate classes from xsd files. I want to continue the current project structure so i want jaxb2-maven-plugin to generate the classes in a specific location. I have multiple schemes and want to generate the classes in different locations. I'm using multiple plugin execution bindings in order to do that as instructed in the JAXB-2 Maven plugin site.
My problem is that only the first execution is performed. None of the classes in the second execution are generated.
Here is my POM.xml file relevant part:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>schema1</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<schemaDirectory>${basedir}/src/main/resources/schemes</schemaDirectory>
<schemaFiles>myschema1.xsd</schemaFiles>
<packageName>xml</packageName>
<outputDirectory>${basedir}/src/main/java/com/example/dor/a</outputDirectory>
<arguments>-extension -Xcloneable -Xdefault-value -Xsetters -Xannotate</arguments>
<staleFile>${build.directory}/.jaxb-staleFlag-1</staleFile>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
<execution>
<id>schema2</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<schemaDirectory>${basedir}/src/main/resources/schemes</schemaDirectory>
<schemaFiles>myschema2.xsd</schemaFiles>
<packageName>xml</packageName>
<outputDirectory>${basedir}/src/main/java/com/example/dor/b</outputDirectory>
<arguments>-extension -Xcloneable -Xdefault-value -Xsetters -Xannotate</arguments>
<staleFile>${build.directory}/.jaxb-staleFlag-1</staleFile>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</executions>
</plugin>
An update answer using version 2.5.0 of the plugin. This would be the configuration:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
<executions>
<execution>
<id>schema1</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<packageName>com.your.package</packageName>
<sources>
<source>${project.basedir}/src/main/resources/xsd/sample1/sample1.xsd</source>
</sources>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
<execution>
<id>schema2</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<packageName>com.your.package</packageName>
<sources>
<source>${project.basedir}/src/main/resources/xsd/sample2/sample2.xsd</source>
</sources>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</executions>
</plugin>
Hope it helps for newer configurations.
I would upgrade to 1.6, and you will have to put the 2 schemas in different packages to stop a conflict in the generated ObjectFactory. Below works for me:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>schema1</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<schemaDirectory>${basedir}/src/main/resources/schemes</schemaDirectory>
<schemaFiles>myschema1.xsd</schemaFiles>
<packageName>xml.a</packageName>
<outputDirectory>${basedir}/src/main/generated1</outputDirectory>
<clearOutputDir>true</clearOutputDir>
</configuration>
</execution>
<execution>
<id>schema2</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<schemaDirectory>${basedir}/src/main/resources/schemes</schemaDirectory>
<schemaFiles>myschema2.xsd</schemaFiles>
<packageName>xml.b</packageName>
<outputDirectory>${basedir}/src/main/generated2</outputDirectory>
<clearOutputDir>true</clearOutputDir>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Had the same problem.
Enabled the -X option of maven to see why the second generation is not performed.
The second generation was not run because the staleFile was the same. I had to add to both executions the parameter staleFile having different values:
<staleFile>${project.build.directory}/jaxb2/.xjcStaleFlag1</staleFile>
........
<staleFile>${project.build.directory}/jaxb2/.xjcStaleFlag2</staleFile>
I have configured failsafe together with tomcat7-maven-plugin for making integration-test. It's great and works very well when I type:
mvn clean verify -P integration-test
My pom.xml is like that:
<!-- Runs integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18</version>
<executions>
<!-- Invokes both the integration-test and the verify goals of the Failsafe Maven plugin -->
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<!-- Skips integration tests if the value of skip.integration.tests property is true -->
<skipTests>${skip.integration.tests}</skipTests>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/onde-vou</path>
</configuration>
<executions>
<execution>
<id>start-tomcat</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<fork>true</fork>
</configuration>
</execution>
<execution>
<id>stop-tomcat</id>
<phase>post-integration-test</phase>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
</executions>
</plugin>
But I got an unexpected behavior. When I type:
mvn clean install
It starts the tomcat and shutdown at the end of the process.
How do I avoid this behavior? It is useless for me and I lose some secs.
You can try mvn clean install -Dmaven.test.skip=true which skip the test, hence skips the execution pre-integration-test
or remove
<executions>
<execution>
<id>start-tomcat</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<fork>true</fork>
</configuration>
</execution>
<execution>
<id>stop-tomcat</id>
<phase>post-integration-test</phase>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
</executions>
Can I get h2 to support Postgres array syntax
CREATE TABLE artists
(
release_id integer,
artist_name text,
roles text[]
)
I use h2 to mimic Postgres in my unit tests, but it doesn't like the above DDL because of the definition of roles (if I comment out that column it works). H2 does have an ARRAY datatype is there a way I can write so that my code would work with either h2 or postgres
In fact, you can define integration tests with real postgres DB instead of h2.
It will be more usefull.
The main idea is to run docker instances with dependencies(postgres DB) before integration tests and shut down after.
Here is an example with maven:
First define rules:
<plugin>
<!-- define Integration tests -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<systemPropertiesFile>${ports.env.file}</systemPropertiesFile>
<includes>
<include>**/*IT.*</include>
</includes>
<additionalClasspathElements>
<additionalClasspathElement>resources</additionalClasspathElement>
</additionalClasspathElements>
<systemPropertiesFile>${it.ports.env.file}</systemPropertiesFile>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
Then need to get free ports for your dependencies (for example postgres DB)
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>reserve-network-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<portNames>
<portName>DB_PORT</portName>
</portNames>
<outputFile>${it.ports.env.file}</outputFile>
</configuration>
</execution>
</executions>
</plugin>
Then you should run and stop docker containers with dependency-services (postgres):
<plugin>
<groupId>com.dkanejs.maven.plugins</groupId>
<artifactId>docker-compose-maven-plugin</artifactId>
<version>4.0.0</version>
<configuration>
<envFile>${it.ports.env.file}</envFile>
<envVars>
<COMPOSE_HTTP_TIMEOUT>120</COMPOSE_HTTP_TIMEOUT>
</envVars>
<services>
<service>db-postgres-test</service>
</services>
<composeFiles>
<composeFile>${session.executionRootDirectory}/docker-compose.db-only.yml
</composeFile>
</composeFiles>
<detachedMode>true</detachedMode>
</configuration>
<executions>
<execution>
<id>up</id>
<phase>pre-integration-test</phase>
<goals>
<goal>up</goal>
</goals>
</execution>
<execution>
<id>down</id>
<phase>post-integration-test</phase>
<goals>
<goal>down</goal>
</goals>
<configuration>
<removeVolumes>true</removeVolumes>
<removeOrphans>true</removeOrphans>
</configuration>
</execution>
</executions>
</plugin>
This solution helps me with the same problem earlier.
I hope, it will help you.
I'm trying to get pre and post integration phase to work with maven, to no avail.
My goal is to set up and tear down integration tests by running some binaries that are necessary. I'm testing with antrun-plugin and exec-plugin, but none of them prints the messages.
I'm running mvn verify. If I bind the plugins to clean phase and run mvn clean, the echo message and the ls are shown.
What's wrong? I'm using maven3
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12.3</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>ls</executable>
<arguments>
<argument>-la</argument>
</arguments>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>xxx</id>
<configuration>
<target>
<echo>Cleaning deployed website</echo>
</target>
</configuration>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I helped someone else get the failsafe plugin configured correctly earlier. Try explicitly specifying the phases in the failsafe plugin executions. Not sure why that is needed, as the failsafe plugin docs say the goals are supposed to be bound to correct phases by default - but it seems to be.