I have multi module project -
Parent
1- controller module - has unit tests
2- service module - has unit tests
3- integration test module - Rest assured Api testing
I have integrated jacoco in parent's pom.xml.
Jacoco.exec are getting generated for all the unit tests but jacoco-it.exec not getting generated for integration test module. However surefire-reporst are getting generated. Please suggest if I am missing anything? Do I need to add anything on integration-test-module's pom.xml ? All my plugins are in parent's pom.xml
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<executions>
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/coverage-reports/jacoco-it.exec</destFile>
<propertyName>failsafeArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/coverage-reports/jacoco-it.exec</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.15</version>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<argLine>${failsafeArgLine}</argLine>
<skipTests>${skip.integration.tests}</skipTests>
</configuration>
</execution>
</executions>
</plugin>
You need to use #{failsareArgLine} in the failsafe configuration argLine property, as cited in the documentation (so basically an # instead of $), otherwise failsafe will not use the property set by JaCoCo. In my project, at least, this was the only thing that was missing.
Related
i am trying to get jacoco working, so it reports me my
code coverage of my integration tests. Currently i have this
setup
parent.pom
-- module1
-- module2
-- module3
-- module4
-- report
module 1 to 3 contains my source code, while module 4 contains a
client, which runs the integration tests.
parent.pom includes the jacoco-plugin:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>prepare-unit-test-agent</id>
<phase>generate-test-sources</phase>
<configuration>
<append>true</append>
<destFile>${project.build.directory}/jacoco.exec</destFile>
</configuration>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>prepare-it-test-agent</id>
<phase>pre-integration-test </phase>
<configuration>
<propertyName>failsafeArgLine</propertyName>
<destFile>${project.build.directory}/jacoco-it.exec</destFile>
<append>true</append>
</configuration>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>verify</phase>
<goals>
<goal>report-integration</goal>
</goals>
</execution>
</executions>
</plugin>`
report pom:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>it-report</id>
<phase>verify</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
<configuration>
<dataFileIncludes>
<dataFileInclude>**/jacoco.exec</dataFileInclude>
<dataFileInclude>**/jacoco-it.exec</dataFileInclude>
</dataFileIncludes>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-overall</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
in my report module, all other modules are imported as dependencie
with scope = compile.
Now, the generated Coverage, only shows that the tests cover takes
place in module 1. Since the logic is something like this: Module 3
= Interface Module 2 = Implementation of the Interfaces Module 1 = entities
it is strange that the Code of Module 2 and 3 are not shows as
covered. All the tests call methods from Module 3.
Just for side info: Source is in Java, Tests are in groovy
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>
When trying to get failsafe bound to the lifecycle, nothing is executed at all. I have read this guide and this related question, and according to this information, it should be possible to make maven execute an the goal integration-test of failsafe in the integration-test, when I specify it in the build/pluginManagement/plugins-section in the pom.xml like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<configuration>
<includes>
<include>**/*IT</include>
</includes>
</configuration>
<executions>
<execution>
<id>failsafe-integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>failsafe-verify</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
Unfortunately, this does not force maven to run failsafe:integration-test at all (neither with mvn integration-test nor mvn verify)
But if I try to use failsafe with the plugin-specification like this (from here with added configuration):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<includes>
<include>**/*IT</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
At least maven compile failsafe:integration-test runs. But unfortunately, this does not call pre- and post-integration-test. I am struggeling for this for a while now, and have no clue - it should be bound as it is.
Does anybody know why this happens, or how I can fix it?
The thing you did is to define it only in pluginManagement but you have to run it really like this. The definition in pluginManagement is good practice to pin the version of the plugin.
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
Apart from that it's not necessary to give include rules for the maven-failsafe-plugin cause it has already defaults defined so no need for that.
I am trying to get a JBehave story to execute in Maven it is completely ignoring the JBehave plugin. I've spent several hours using different configurations but it looks like the plugin isn't being executed at all. Any recommendations/tips would be appreciated!
All my JBehave classes live in:
src/at/java
Relevant parts of my pom.xml:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/at/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<executions>
<execution>
<id>run-stories-as-embeddables</id>
<phase>integration-test</phase>
<configuration>
<includes>
<include>**/*.java</include>
</includes>
</configuration>
<goals>
<goal>run-stories-as-embeddables</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.11</version>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/*.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
Best is to change the location of your test classes to src/test/java and change the name of the stories based on the documentation of JBehave.
JBehave running with maven follow the Maven rules for location of code and text artifacts.
For test scope you must put them in src/test/java and src/test/resources. For compile scopes is src/main/java and src/main/resources.
With JBehave with maven you could use two scopes (test or compile), you just need to set which one you want in the plugin configuration, so you choose where to put your artifacts. it defaults to compile.
In your case you are adding a new test source so you must set the scope to test:
see detail here.
Maybe the jbehave-maven-plugin could not find the compiled test classes (scenarios) because it looks in the wrong classpath.
Please look at your target directory and search the embeddable classes -> target/classes or target/test-classes?
To solve the problem i must set the scope of jbehave-maven-plugin to test in the configuration of my project pom.xml.
here is a example
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<executions>
<execution>
<id>run-stories-as-embeddables</id>
<phase>integration-test</phase>
<goals>
<goal>run-stories-as-embeddables</goal>
</goals>
<configuration>
<scope>test</scope>
<includes>
<include>**/*Scenarios.java</include>
</includes>
<ignoreFailureInStories>true</ignoreFailureInStories>
<ignoreFailureInView>false</ignoreFailureInView>
</configuration>
</execution>
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.