I am pleased to inform you that our issue is resolved.
I would like to share the fix so that anyone facing the same issue may get the help.
Possible Causes:
- Unit test cases are missing.
- sonar-maven-plugin is not defined in pom.xml file.
- Language and tool-specific maven plugin (for an example, Jacoco) is not defined in pom.xml
- Jacoco plugin related configuration in pom.xml is not correct.
Solutions:
-
SonarQube doesn’t run your tests or generate reports. It only imports pre-generated reports. We have to use language and tool-specific analysis parameters for importing coverage and execution reports. Please ensure that you have at least one unit test case defined for your project.
-
Please ensure that sonar-maven-plugin is defined in pom.xml:
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.7.0.1746</version>
</plugin>
- Please ensure that jacoco related configuration is correct:
<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>
<phase>test-compile</phase>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
<phase>test</phase>
</execution>
</executions>
</plugin>
- If your jacoco reports are generated at custom path (other than default path: target/site/jacoco/jacoco.xml ) OR if you are using deprecated sonar property( sonar.jacoco.reportPaths ) for jacoco then please update sonar property as below:
<sonar.coverage.jacoco.xmlReportPaths>your/custom/path/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
Reference: Test Coverage & Execution | SonarQube Docs