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.
Best Answer
You should not invoke the agent after the install phase but before, so instead of invoking:
You should invoke
The main reason is: the agent will not participate to the build lifecycle, the
test
phase will already be executed as part of theinstall
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:
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 beendataFile
instead. The same applies todestFile
.The
prepare-agent
goal is already using${project.build.directory}/jacoco.exec
as defaultdestFile
value, the same applied to thedataFile
value for thereport
goal. The main reason for this change would be a more flexible and standard build, not relying onartifactId
as project name (the default, but still not mandatory) and using the more generic${project.build.directory}
property instead to point directly attarget
.Final note: make sure to configure the Jacoco Plugin executions within the
build/plugins
section and notbuild/pluginManagement/plugins
section. ThepluginManagement
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 underbuild/plugins
.As per official Maven POM reference
(note: bold is mine)