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. But the sonarqube job is not able to show that things overage the webpage. 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.

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

Script:- script: gradle sonar -Dsonar.login=$SONAR_TOKEN -Dsonar.host.url=$SONAR_HOST_URL -Dsonar.java.binaries=./build/ -Dsonar.coverage.jacoco.xmlReportPaths=.build/reports/jacoco/jacocoTestReport.xml

This is the one commonly created for the build:-

image

Hey there.

What do the logs say about the import of the report you’re specifying?

Hi @Colin, 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 "3.5.0.2730"
}

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:-

sonarqube-check:
  stage: sonarqube-check
  image: gradle:6.6.0-jdk11
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
    GIT_DEPTH: "0"  #
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script: 
    - gradle sonar -Dsonar.login=$SONAR_TOKEN 
        -Dsonar.login=$SONAR_TOKEN
        -Dsonar.exclusions=**/model/**
        -Dsonar.host.url=$SONAR_HOST_URL

In your script block, you should be able to do something like cat build/reports/jacoco/jacocoTestReport.xml to see if it really exists or not.

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

1 Like