I have a Java project consisting on multiple modules. Some functions for a common package are tested within the other modules. Sonar only shows the code coverage tested inside each package, how can I tell it to search in all the modules?
I am using SonarQube 4.5.4, Java 8 and JUnit 4.12
You have to provide SonarQube with a single JaCoCo report aggregating data from all the modules.
In the parent POM, define a location for this aggregated JaCoCo report:
<properties>
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
</properties>
and configure JaCoCo (especially <destFile>
)
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6.201602180812</version>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
In each module, tell JaCoCo to aggregate the coverage data to this global JaCoCo report file:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
</configuration>
</plugin>
You can have a look at this project: https://github.com/racodond/sonar-css-plugin that produces an aggregated JaCoCo report used by SonarQube: https://sonarqube.com/dashboard/index?id=org.codehaus.sonar-plugins.css%3Acss
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.