JaCoCo with Maven - missing execution data file - java

We have a Maven multi module project consisting of a parent (HelloWorld) and different children (HelloWorldServices and HelloWorldPresentation) and use Jenkins to build.
The error after running the successful test is
[INFO] --- jacoco-maven-plugin:0.7.6.201602180812:report (default-cli) # HelloWorldServices ---
[INFO] Skipping JaCoCo execution due to missing execution data file:/var/lib/jenkins/workspace/HelloWorld/HelloWorldServices/target/jacoco.exec
The lines before it says
[INFO] --- jacoco-maven-plugin:0.7.6.201602180812:prepare-agent (default-cli) # HelloWorldServices ---
[INFO] argLine set to -javaagent:/var/lib/jenkins/.m2/repository/org/jacoco/org.jacoco.agent/0.7.6.201602180812/org.jacoco.agent-0.7.6.201602180812-runtime.jar=destfile=/var/lib/jenkins/workspace/HelloWorld/HelloWorldServices/target/jacoco.exec
This is how I defined the parent pom JaCoCo plugin:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6.201602180812</version>
<configuration>
<destfile>${project.artifactId}/target/jacoco.exec</destfile>
<datafile>${project.artifactId}/target/jacoco.exec</datafile>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
In no pom did I explicitly mention surefire. I also tried what you find everywhere to put the argLine in the configuration but all with the same result. The JaCoCo .exec file has never been created, no matter what I do. As for the goals, I use
mvn clean install jacoco:prepare-agent jacoco:report
Since when I omit the jacoco goals, it doesn't even display the INFO message.

You should not invoke the agent after the install phase but before, so instead of invoking:
mvn clean install jacoco:prepare-agent jacoco:report
You should invoke
mvn clean jacoco:prepare-agent install jacoco:report
The main reason is: the agent will not participate to the build lifecycle, the test phase will already be executed as part of the install phase, then Maven will execute the agent as per command line invocation, but it will be too late.
You should probably also change the plugin configuration above to:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6.201602180812</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Note: I removed the configuration section, because it was actually pointing to default values. Moreover, XML elements are case sensitives here, so your datafile element was simply ignored, it should have been dataFile instead. The same applies to destFile.
The prepare-agent goal is already using ${project.build.directory}/jacoco.exec as default destFile value, the same applied to the dataFile value for the report goal. The main reason for this change would be a more flexible and standard build, not relying on artifactId as project name (the default, but still not mandatory) and using the more generic ${project.build.directory} property instead to point directly at target.
Final note: make sure to configure the Jacoco Plugin executions within the build/plugins section and not build/pluginManagement/plugins section. The pluginManagement section is meant for governance and common harmonization of versions or configurations, but it will be ignored if the corresponding plugin would not be declared under build/plugins.
As per official Maven POM reference
pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one. However, this only configures plugins that are actually referenced within the plugins element in the children. The children have every right to override pluginManagement definitions.
(note: bold is mine)

JaCoCo reports get created from the execution data file.
If this file is not present then JaCoCo report goal skips the report creation.
So it is compulsory to create the execution data file.
Reasons due to which execution data file will not get created are the following
- Tests are not present.
- All tests are ignored.
- Surefire plugin is missing.
- JaCoCo's prepare-agent goal is not executed, which sets argLine which is needed to configure to surefire.
- Surefire plugin is not configured with JaCoCo's agent.

I think that "destfile" and "datafile" are case sensitive so try to replace them with "destFile" and "dataFile", maybe it'll work :)

I just dealt with this issue today and found out that this happening when I set the argLine parameter in Surefire plugin (which I needed to do for running JavaFx-related tests) which replaces the default even after you have prepare-agent in your jacoco-maven-plugin goals.
So basically, the solution is to add the original argLine and append your additional arg lines using #{argLine} as noted here:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<argLine>#{argLine} --enable-native-access ALL-UNNAMED --add-modules jdk.incubator.foreign</argLine>
</configuration>
</plugin>
It mentioned in that post to assign the jacoco agent argline variable ${surefire.argLine} but i think those steps are not necessary (at least not in my case).

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<configuration>
<target>
<propertyfile file="lombok.config">
<entry key="config.stopBubbling" value="true" />
<entry key="lombok.addLombokGeneratedAnnotation" value="true" />
</propertyfile>
</target>
<excludes>
<exclude>**/domain/**</exclude>
<exclude>**/enumeration/**</exclude>
<exclude>**/exception/**</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- attached to Maven test phase -->
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<!-- Add this checking -->
<execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>PACKAGE</element>
<limits>
<limit>
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>65%</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>

I share with you my response may be someone else work for him
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<!-- <configuration>
<excludes>
<exclude>package you want exclude</exclude>
</excludes>
</configuration>-->
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- attached to Maven test phase -->
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<!-- <execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>PACKAGE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.9</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>-->
</executions>
</plugin>

Related

Is prepare-agent goal is necessary in jacoco-maven-plugin?

In My project, if I write pom like this:
...
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>post-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
...
it will not generate report in my project after i run mvn install.
but i change it to
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>pre-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>post-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
it worked!!
I want to know what was the different?
I read the offical document here: http://www.jacoco.org/jacoco/trunk/doc/prepare-agent-mojo.html
the goal prepare-agent is just for set property for jvm agent, not start jvm agent, why it is necessary?
Well the link shared by you over prepare:agent already reads much of it:
Prepares a property pointing to the JaCoCo runtime agent that can be
passed as a VM argument to the application under test.
So if the goal is not bound to the plugin execution, then the default behavior for the property would be either argLine or tycho.testArgLine for packaging type eclipse-test-plugin.
In your case, if we assume its argLine, and your project defines the VM arguments for test execution, you need to make sure that they include this property.
One of the ways to do this in case of maven-surefire-plugin - is to
use syntax for late property evaluation:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>#{argLine} -your -extra -arguments</argLine>
</configuration>
</plugin>
The detailed Java Agent doc, can help you understand deeper how Jacoco uses its own agent to provide a mechanism that allows in-memory pre-processing of all class files during class loading independent of the application framework.

How to make Maven unit test code coverage work

In Eclipse, I have used EcLEmma to see the unit test code coverage. Which worked fine.
Therefore I have tried to use the JaCoCo plugin for Maven to see the same report with Surefire from Maven build, or even better, with a certain profile, or in the site cycle. Without success. All suggested solutions here didn't work for me.
What is the best way to get a unit test code coverage report (with surefire)?
[Edit]
to be more specific why jacoco failed for me.... as I got always the
Skipping JaCoCo execution due to missing execution data
from the pom
in the properties
<jacoco.it.execution.data.file>${project.build.directory}/coverage-reports/jacoco-it.exec</jacoco.it.execution.data.file>
<jacoco.ut.execution.data.file>${project.build.directory}/coverage-reports/jacoco-ut.exec</jacoco.ut.execution.data.file>
in the Build section
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<versionRange>${jacoco.version}</versionRange>
<executions>
<!-- Prepares the property pointing to the JaCoCo runtime agent
which is passed as VM argument when Maven the Surefire plugin is executed. -->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution
data. -->
<destFile>${jacoco.ut.execution.data.file}</destFile>
<!-- Sets the name of the property containing the settings for
JaCoCo runtime agent. -->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<!-- Ensures that the code coverage report for unit tests is created
after unit tests have been run. -->
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution
data. -->
<dataFile>${jacoco.ut.execution.data.file}</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
</configuration>
</execution>
<!-- Prepares the property pointing to the JaCoCo runtime agent
which is passed as VM argument when Maven the Failsafe plugin is executed. -->
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution
data. -->
<destFile>${jacoco.it.execution.data.file}</destFile>
<!-- Sets the name of the property containing the settings for
JaCoCo runtime agent. -->
<propertyName>failsafeArgLine</propertyName>
</configuration>
</execution>
<!-- Ensures that the code coverage report for integration tests
after integration tests have been run. -->
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution
data. -->
<dataFile>${jacoco.it.execution.data.file}</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
</configuration>
</execution>
</executions>
</pluginExecutionFilter>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
was my last try but the pom becomes bigger and bigger without any result
which failes with
configuring report plugin org.apache.maven.plugins:maven-jxr-plugin:2.3
configuring report plugin org.jacoco:jacoco-maven-plugin:0.7.5.201505241946
Skipping JaCoCo execution due to missing execution data file:......\target\jacoco.exec
Skipping JaCoCo execution due to missing execution data file:......\target\jacoco-it.exec
.... => long project path
Thanks user3732793
Personnaly, I only needed to add this to my pom.xml
<project>
...
<dependencies>
...
</dependencies>
<build>
<plugins>
...
<!-- Code Coverage report generation -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>generate-code-coverage-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Then I am running
mvn test
and I get the HTML report under ./target/site/jacoco/*.html
As always the solution is easy after reading the documentation which provides example poms jacoco documentation.
This profile:
<profile>
<id>test</id>
<properties>
<env>test</env>
<gebEnv>test</gebEnv>
<jacoco.skip>false</jacoco.skip>
<maven.test.skip>false</maven.test.skip>
<skip.unit.tests>false</skip.unit.tests>
</properties>
</profile>
This in the build section:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
And this in the reporting section:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
</plugin>
Than this does all:
mvn clean install site -P test

Maven: execution from command line and multiple executions in config

I would like to execute a plugin goal from command line but perform multiple executions of the plugin. To this end my POM looks like this:
<plugin>
<groupId>xxx.yyy</groupId>
<artifactId>zzz</artifactId>
<version>1.1.6</version>
<executions>
<execution>
<id>default-cli-1</id>
<goals>
<goal>mygoal</goal>
</goals>
<configuration>
.... config1 ....
</configuration>
</execution>
<execution>
<id>default-cli-2</id>
<goals>
<goal>mygoal</goal>
</goals>
<configuration>
.... config2 ....
</configuration>
</execution>
</executions>
</plugin>
What I would like to do is something like:
mvn xxx.yyy.zzz:mygoal
and that would then execute the two executions. But I cannot figure out how.
I'm aware that I cannot use an <id> when executing from the command line. That is what the default-cli is for. However the <id> must be unique within <executions> which means I can only put the default-cli on one execution.
Maven version 3.0.5.
You can execute a goal (and its execution) from command line starting from Maven 3.3.1 on and this new feature, via the #executionId additional option.
Concerning Maven and execution ids generation, you can also check this SO question.
Before Maven 3.3.1 you could instead bind the two executions to a phase which would normally not harm (like validate) and have something like the following:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>execution-1</id>
<phase>validate</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>something1</classifier>
</configuration>
</execution>
<execution>
<id>execution-2</id>
<phase>validate</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>something2</classifier>
</configuration>
</execution>
</executions>
</plugin>
Then executing:
mvn validate
You will effectively execute the two executions of the same goal of the same plugin, as part of an harmless phase.
If you don't want to have them as part of this phase by default (understandable), then you can move them to a profile and activate it as part of the execution:
mvn validate -PpluginGoalExecution
For completeness, the profile would look like:
<profile>
<id>pluginExecution</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>execution1</id>
<phase>validate</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>something1</classifier>
</configuration>
</execution>
<execution>
<id>execution2</id>
<phase>validate</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>something2</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
And it goes without saying: the id of the profile should in this case be quite self explanatory about which plugin and which goal it would actually execute (that is, the purpose of the profile, as usual).
Update
Just cosmetic, but you could also add to the profiled build above the element:
<defaultGoal>validate</defaultGoal>
So that you would only need to run the following Maven command (only profile activation):
mvn -PpluginGoalExecution
And it would then automatically execute the validate phase and the configured plugin executions. Not a big change (as I said, cosmetic), but maybe closer to a plugin goal execution rather than a Maven phase invocation (again, just appearance).

Maven JAXB plugin executing only one excecution

I am trying to generated sources from two XSD schemas. My JAXB maven plugin looks like this:
<plugin>
<groupId>com.sun.tools.xjc.maven2</groupId>
<artifactId>maven-jaxb-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<id>GenerateKenexa</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<includeBindings>
<includeBinding>**/jaxb-bindings-kenexa.xml</includeBinding>
</includeBindings>
<includeSchemas>
<includeSchema>**/KenexaXMLConfiguration.xsd</includeSchema>
</includeSchemas>
</configuration>
</execution>
<execution>
<id>GenerateTalentQ</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<includeBindings>
<includeBinding>**/jaxb-bindings-talentq.xml</includeBinding>
</includeBindings>
<includeSchemas>
<includeSchema>**/TalentQXMLConfiguration.xsd</includeSchema>
</includeSchemas>
</configuration>
</execution>
</executions>
</plugin>
The first one gets generated fine. But the second one does not. I see in the maven output:
[INFO] --- maven-jaxb-plugin:1.1.1:generate (GenerateKenexa) # online.tests.management ---
[INFO] Compiling file:/D:/Projects/GTIWebApplications/gti_online_tests_management/src/main/resources/xsd/KenexaXMLConfiguration.xsd
[INFO] Writing output to D:\Projects\GTIWebApplications\gti_online_tests_management\target\generated-sources\xjc
[INFO]
[INFO] --- maven-jaxb-plugin:1.1.1:generate (GenerateTalentQ) # online.tests.management ---
[INFO] files are up to date
It says that files are up to date, but they aren't even generated. What might be wrong?
For people coming in to this question as I did, a year later :/
The problem persists in maven-jaxb2-plugin aswell, it's probably some sort of bug in 0.8.3.
When you generate the files into the same directory, the plugin "thinks" that the files have allready been generated and skips that second execution.
I found that in order to generate the second execution you will have to set the argument
<forceRegenerate>true</forceRegenerate>
In the configuration section.
I solved the problem. I have changed the maven jaxb plugin into maven jaxb2 plugin and now everything works. Now my maven configuration looks like this:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<id>GenerateKenexa</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/xsd</schemaDirectory>
<schemaIncludes>
<include>KenexaXMLConfiguration.xsd</include>
</schemaIncludes>
<generatePackage>com.groupgti.onlinetest.kenexa.jaxb</generatePackage>
<generateDirectory>${project.build.directory}/generated-sources/kenexa</generateDirectory>
</configuration>
</execution>
<execution>
<id>GenerateTalentQ</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/xsd</schemaDirectory>
<schemaIncludes>
<include>TalentQXMLConfiguration.xsd</include>
</schemaIncludes>
<generatePackage>com.groupgti.onlinetest.talentq.jaxb</generatePackage>
<generateDirectory>${project.build.directory}/generated-sources/talentq</generateDirectory>
</configuration>
</execution>
</executions>
</plugin>
I am using jaxb2 while still was facing the problem when I reached here. I added the below piece into config from other folks answers and it works now.
For previous answers the part that did the trick should be:
<generateDirectory>${project.build.directory}/generated-sources/kenexa</generateDirectory>
Also a unique execution id is needed
<id>GenerateKenexa</id>
But different directories make the code lies into two top level packages, so at last I am using:
<forceRegenerate>true</forceRegenerate>
First, I would recommend to specify separate output folders for each xsd <outputdirectory>${basedir}/target/generated-sources/xjc</outputdirectory>
And second, try to set it up as separate plugin entries, no separate executions:
<plugin>
<groupId>com.sun.tools.xjc.maven2</groupId>
...
<includeSchema>**/KenexaXMLConfiguration.xsd...
...
</plugin>
<plugin>
<groupId>com.sun.tools.xjc.maven2</groupId>
...
<includeSchema>**/TalentQXMLConfiguration.xsd...
...
</plugin>

Maven2 compiler custom execution source directory and target directory

I want to run the maven compiler plugin in a different phase and with different sourceDirectories and destinationDirectories such that code from directories other than src/main/java and src/test/java can be used.
I thought the solution would look something like the below, where the phase I was linking it to was pre-integration-test. However the properties for testSourceDirectory and testOutputDirectory don't seem to be specified in this way as they are in the section of the POM.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>compile mytests</id>
<goals>
<goal>testCompile</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<testSourceDirectory>${basedir}/src/inttest/java</testSourceDirectory>
<testOutputDirectory>${basedir}/target/inttest-classes</testOutputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Is there a way to get this plug-in to compile different directories in different phases without affecting its default operation?
The source directories are set outside the compiler-plugin inside the <build> element, so this won't work.
You can use the build-helper-maven-plugin's add-source and add-test-source to specify additional source directories for your integration tests, but this will not remove the existing source dirs.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>add-it-source</id>
<phase>pre-integration-test</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/src/inttest/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
If you bind the add-test-source goal to run just before the testCompile goal, your integration tests will be included. Note you want them to be output to target/test-classes so the surefire plugin will find them.
To handle removal of the standard test sources, I wrote a small plugin to modify the model to remove existing testSource locations before adding the ones for integration tests.
After more research it is apparent this is not actually possible in Maven 2 in the way I want, a hack of some form is necessary to introduce integration tests. While you can add additional directories (as suggested by Rich Seller) there is no plugin to remove the other sources or to compile a directory separately from the main compilation.
The best solution I have found for adding integration tests is to first use the build helper plugin to add the directory inttest directory to be compiled as tests.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/inttest/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
Now in order to get the integration tests to execute on the integration-test phase you need to use excludes and includes to manipulate when they get run as below. This allow any custom parameters you might want (in my case an agent being added via argline).
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/itest/**</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>inttests</id>
<goals>
<goal>test</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<excludes><exclude>none</exclude></excludes>
<includes>
<include>**/itest/**/*Test.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>

Categories

Resources