We have a multi-module maven project and use the JaCoCo Maven plugin to generate the reports. For CI, we use Bamboo and SonarQube. However, in SonarQube the code coverage is always 0% although the JaCoCo reports do exist and according to build log, they also are imported by SonarQube.
Project Structure:
Module (root pom.xml)
--- module
--- module.feature
--- module.repository
--- module.doc
--- module.tests
The root pom.xml looks like this:
<modules>
<module>module</module>
<module>module.tests</module>
<module>module.feature</module>
<module>module.repository</module>
<module>module.doc</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-report-aggregate</id>
<phase>verify</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
<configuration>
<outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
We also have an aggregator pom.xml where all the test plugins are defined etc.
With this config, JaCoCo reports in XML format are created in module.tests\target\site\jacoco. Looking at the HTML version, the report seems to be correct.
There are also empty JaCoCo reports created for the other modules, e.g. in module.doc\target\site\jacoco or module.feature\target\site\jacoco.
In the Bamboo build log we can see this for all modules:
[INFO] Sensor JaCoCo XML Report Importer [jacoco]
[INFO] Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
[INFO] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=28ms
Initial thought was that maybe there is a conflict with empty reports so we also tried to put the report-aggregate goal only into the module.tests pom.xml which results into only one JaCoCo report but still no coverage in SonarQube.
In the Bamboo build log we would see this for the module.tests:
[INFO] Sensor JaCoCo XML Report Importer [jacoco]
[INFO] Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
[INFO] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=28ms
For all other modules, the Bamboo build log would show this:
[INFO] Sensor JaCoCo XML Report Importer [jacoco]
[WARNING] No coverage report can be found with sonar.coverage.jacoco.xmlReportPaths='target/site/jacoco/jacoco.xml'. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
[INFO] No report imported, no coverage information will be imported by JaCoCo XML Report Importer
[INFO] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=1ms
Both variants (report-aggregate in the root pom.xml OR only in the module.tests pom.xml) still result in 0% coverage in SonarQube.
As you can see from the log, we have set the sonar property sonar.coverage.jacoco.xmlReportPaths accordingly. No other sonar properties have been set.
Hint: when using the report goal instead report-aggregate, the SonarQube coverage was showing but only for the test classes. So the integration between Bamboo and SonarQube seems to be there somehow.
- What am I missing here?
- Are some sonar properties maybe missing?