We have a multimodule java maven project like this:
parent
- child 1
- child 2
- common
We would like a code coverage report per sub module (not one global one for the entire project).
this page: Java test coverage | SonarQube Server Documentation
Says we just need to add this to the parent pom:
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.13</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
<configuration>
<formats>
<format>XML</format>
</formats>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
When we run mvn test
or mvn clean verify
in the parent dir, we get this:
[INFO] — jacoco:0.8.13:prepare-agent (prepare-agent) @ my-service —
[INFO] argLine set to -javaagent:C:\Users\me\.m2\repository\org\jacoco\org.jacoco.agent\0.8.13\org.jacoco.agent-0.8.13-runtime.jar=destfile=C:\Users\me\dev\my-service\target\jacoco.exec
The issue is my-service is the root (parent) dir, and there is no target directory, only the sub modules contain code and target directories.
So there do not seem to be any jacoco.exec generated
The sonar doc says:
“By default, the generated report will be saved under target/site/jacoco/jacoco.xml
”
But this dir does not exist.
If I push the above changes to the PR, it re runs the sonar pipeline, and in the output I see:
`[INFO] argLine set to -javaagent:/root/.m2/repository/org/jacoco/org.jacoco.agent/0.8.13/org.jacoco.agent-0.8.13-runtime.jar=destfile=/opt/atlassian/pipelines/agent/build/target/jacoco.exec`
`[INFO] --- jacoco:0.8.13:report (report) @ my-service ---`
`[INFO] Skipping JaCoCo execution due to missing execution data file.`
If we look in a target dir of a sub module, we see:
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 15/05/2025 14:34 classes
d----- 17/06/2025 15:15 generated-sources
d----- 17/06/2025 15:15 generated-test-sources
d----- 29/05/2025 17:35 maven-archiver
d----- 29/05/2025 17:35 maven-status
d----- 17/06/2025 15:16 surefire-reports
d----- 29/05/2025 17:35 test-classes
There is no target dir in the parent.
If we instead run “mvn clean verify sonar:sonar” we DO see a directory which is:
parent/target/sonar/
which we dont get if we do mvn test or mvn verify. In this dir, we see some sub dirs like “ir” and “usfg2” but nothing which looks like a jacoco report.
any suggestions? We don’t really know jacoco, we had hoped that sonar would do code coverage. Using the config in the sonar docs doesn’t seem to work. We pay a lot for sonar, but are struggling to get it to work.