Q: I have the following configuration in Multi-module AEM project. I am facing an issue with the code coverage report on SonarQube. I have test cases part of core modules that I want to cover. So I can see that module is appearing in Jenkins but code coverage is not showing up in SonarQube. Any help please?
SonarQube Version: Community Edition Version 8.2
I maven multi-module project. (AEM)
Base POM file
- Child M1(all)
- Child M2 (core) -> src/main, src/test (I want to cover all the test cases part of this directory)
- Child M3 (it.tests) -> src/main
Base POM.xml file I have added the following configuration.
#Base pom file
<aggregate.report.dir>target/site/jacoco-aggregate/jacoco.xml</aggregate.report.dir>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.language>java</sonar.language>
# Under properties section I have mentions the sonar coverage path
<properties>
<sonar.coverage.jacoco.xmlReportPaths>${basedir}/${aggregate.report.dir}</sonar.coverage.jacoco.xmlReportPaths>
</properties>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.7.0.1746</version>
</plugin>
</pluginManagement>
# I have added the jacoco profile
<profiles>
<profile>
<id>coverage</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
My M2 (Core) module is having all the test cases.
# Core pom file
# Under properties section I have mentions the sonar coverage path
<properties>
<sonar.coverage.jacoco.xmlReportPaths>${basedir}/${aggregate.report.dir}</sonar.coverage.jacoco.xmlReportPaths>
</properties>
it.test module is having generated jacoco.xml file in target directory.
Pom file configuration in it.tests module.
- I have added the execution goals.
- I have added the Sonar coverage xml path
- Also I have added the dependency of the core project in the same pom.xml file.
<properties>
<junit.version>4.8.2</junit.version>
<sonar.coverage.jacoco.xmlReportPaths>${basedir}/${aggregate.report.dir}</sonar.coverage.jacoco.xmlReportPaths>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<id>report</id>
<goals>
<goal>report-aggregate</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
- Jenkins configuration
- SonarQube configuration
- SonarQube Result
The command I am running from my mac terminal
mvn -X clean verify sonar:sonar \
-Dsonar.projectKey=abc \
-Dsonar.host.url=http://servername:9000 \
-Dsonar.login=token
Also it says analysis successful. But still, code coverage is not showing up in SonarQube.
In Jenkins: I can see the jacoco report. (I am not sure this is correct or not)
#Also if I will go to it.tests/target/…/…/jacoco-aggregate/index.html and open the index.html then I will able to see this. (Please ignore the spell mistakes)