I'm about to set up our medium-size maven multiproject build to use jacoco for its unit tests. Despite the documentation and some similar questions on the net, I still don't understand exactly how to set this up.
I have a parent pom that code modules have as their parent, and I have a separate aggregator pom that lists the modules to build.
My goal is to generate the jacoco data file in each child module, and initially use "report-aggregate" to generate a view of the aggregated data, and then later integrate with SonarQube.
I assume I would put the relevant jacoco settings in the parent pom and aggregator pom. The former for the "prepare-agent" settings for each child module, and the latter for the "report-aggregate".
The following are my changes to the parent pom. I added the reference to the jacoco plugin, and added the one "argLine" setting to the surefire configuration:
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.8</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>jacoco.agent.ut.arg</propertyName>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<forkCount>3</forkCount>
<aggregate>true</aggregate>
<reuseForks>true</reuseForks>
<argLine>@{jacoco.agent.ut.arg} -Xmx1024m -XX:MaxPermSize=256m</argLine>
<testSourceDirectory>${project.build.testSourceDirectory}</testSourceDirectory>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
...
</plugins>
When I run the build, I see in the build for each child module lines like the following:
[INFO] --- jacoco-maven-plugin:0.7.8:prepare-agent (default-prepare-agent) @ usl-parent-pom ---
[INFO] jacoco.agent.ut.arg set to -javaagent:...\\.m2\\repository\\org\\jacoco\\org.jacoco.agent\\0.7.8\\org.jacoco.agent-0.7.8-runtime.jar=destfile=...\\usl-parent-pom\\target\\jacoco.exec
I also added the following to the aggregator pom:
</modules>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.8</version>
<executions>
<execution>
<id>report-aggregate</id>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
When I ran the build, I found that it generated the "jacoco.exec" files in the "target" directory of child modules, but it looks like that's all that it did. I didn't see an aggregated report built.
I then manually ran "mvn jacoco:report-aggregate" from the top level, and it seemed to do some work, and it generated an html tree, but when I viewed it in the browser, I saw that it didn't actually find any data. It showed an empty table, like this:
Element | Missed Instructions | Cov. | Missed Branches | Cov. |
Total | 0 of 0 | n/a | 0 of 0 | n/a |
I'm probably missing multiple important details here. What can I do here?