Unable to see the coverage for Gradle 6.6 project

Hi Team,

I am facing an issue with code coverage, not able to see the code coverage over Sonarqube, we are able to generate the coverage.xml locally as well in GitLab.
Also, we are using multiple classes in Gradle and each of them generates an XML file, so we need a collective date to be shown in the Sonarqube webpage.
Tried multiple ways but that didn’t help me. Would you please guys help me why the coverage report is not showing and how to add multiple gradle classes in one report?

Please let me know if any more details are needed from me.

Gradle: 6.6
Sonarqube: 9.9
Sonarqube check/stage image: gradle:6.6.0-jdk11
Java: 11


How do you run the SonarQube analysis?
If you use the SonarQube Gradle plugin, it should automatically configure it correctly so that the JaCoCo report is processed by the Analysis.
If you use some other way to run the SonarQube analysis, you need to configure the sonar.coverage.jacoco.xmlReportPaths analysis property.
Here is the SonarQube documentation about Java code coverage: Java test coverage

Hi @Vampire , The logs say that jacocTestResport.xml is not able to get it. But if I build the project locally it will be there in the build project and other sub-modules as well.

build.gradle setup:-

plugins {
id “org.sonarqube” version “”

plugins {
id ‘org.barfuin.gradle.jacocolog’ version ‘1.2.3’

apply plugin: ‘java’
apply plugin: ‘jacoco’

jacocoTestReport {
reports {
xml.enabled true

sonar {
properties {
property “sonar.projectKey”, “XYZ”
property “sonar.coverage.jacoco.xmlReportPaths”, “build/reports/jacoco/jacocoTestReport.xml”
property “sonar.exclusions”, “**/*model/**”
property “sonar.qualitygate.wait”, true

Gitlab Stage:-

stage: sonarqube-check
image: gradle:6.6.0-jdk11
SONAR_USER_HOME: “${CI_PROJECT_DIR}/.sonar” # Defines the location of the analysis task cache
GIT_DEPTH: “0” #
key: “${CI_JOB_NAME}”
- .sonar/cache
- gradle sonar -Dsonar.login=$SONAR_TOKEN

You did not make sonar depend on any tasks and you do not call any tasks explicitly.
I wonder you get any sane result at all as you do not even provide the compiled class files to SonarQube which it also needs.
Either add some dependencies or call the tasks additionally from the stage file as documented for the SonarQube Gradle plugin.

Locally it probably only works because you are using a stale jacoco report from a previous run or similar.
Configuring the sonar.coverage.jacoco.xmlReportPaths manually should actually not be necessary.

Hi @Vampire, Really thanks for your help. I have refer documentation about Java code coverage: Java test coverage and resolved my issue.

1 Like