SonarQube doesn't get coverage on the PR analysis

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    We are using Enterprise EditionVersion 8.9.5 (build 50698)

  • what are you trying to achieve
    We are trying to get pull-request analysis code coverage information from SonarQube.
    We have a multi-module Gradle project and run the Sonar task from Gradle. We run the Sonar task from Gradle in Jenkins runs.
    Sonar task ran successfully and is able to post analysis on our On-prem Sonarqube Enterprise server. But coverage information is missing.

  • what have you tried so far to achieve this

Here is our project structure

Root of the project
├── build.gradle.kts
├── MakeFile
├── matcher-domain (module)
│ ├── src
│ └── build.gradle.kts
└── matcher-service (module)
├── src
└── build.gradle.kts

In root build.gradle.kts, we have following definition

sonarqube {
    properties {
        property("sonar.sourceEncoding", "UTF-8")
        property("sonar.projectName", "matcher")
        property("sonar.projectKey", "matcher")
        property(
            "sonar.coverage.jacoco.xmlReportPaths",
            "$projectDir/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml"
        )
    }
}

subprojects {

    apply(plugin = "org.sonarqube")
    apply(plugin = "org.jlleitschuh.gradle.ktlint")
    sonarqube {
        properties {
            property("sonar.sources", "src/main")
            property("sonar.tests", "src/test")
            property(
                "sonar.coverage.jacoco.xmlReportPaths",
                "$projectDir/build/reports/jacoco/test/jacocoTestReport.xml"
            )
        }
    }
}

In matcher-domain/build.gradle.kts

tasks.test {
    dependsOn(tasks.ktlintCheck)
    useJUnitPlatform()
    finalizedBy(tasks.jacocoTestReport)
}

tasks.jacocoTestReport {
    dependsOn(tasks.test) // tests are required to run before generating the report
    reports {
        xml.required.set(true)
    }
}

In matcher-service/build.gradle.kts

tasks.test {
    dependsOn(tasks.ktlintCheck)
    useJUnitPlatform()
    finalizedBy(tasks.jacocoTestReport)
}

tasks.jacocoTestReport {
    dependsOn(tasks.test) // tests are required to run before generating the report
    reports {
        xml.required.set(true)
    }
}

We run the Gradle command in Makefile with the following options
These variables are available in the Jenkins Job

./gradlew clean check sonarqube --debug -Dsonar.language=kotlin \
          -Dsonar.host.url=${SONAR_HOST_URL} \
          -Dsonar.login=${SONAR_LOGIN} \
          -Dsonar.pullrequest.key=${PR_ID} \
          -Dsonar.pullrequest.branch=${PR_BRANCH} \
          -Dsonar.pullrequest.base=master \
          -Dsonar.scm.provider=git

Jenkins build run logs are attached here.
sonarqube-no-coverage-log.txt (49.3 KB)

Can anyone help us here?

Hi,

There’s not actually any detail of the analysis in this log. Could you add -d to the Gradle command to get debug logs?

 
Ann

Hi @ganncamp

I have attached the complete compressed debug log.
sonarqube-no-coverage-log-debug.txt.zip (728.5 KB)

Looking at it briefly and the sonar scanner is able to read coverage XML reports, but still can’t produce the Coverage Information.

2022-06-16T11:21:16.432+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
2022-06-16T11:21:16.432+0000 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Reading report '/home/jenkins/workspace/generated-pipelines/mobility-be-matching/matcher-service/matcher-ci/code-quality/matcher-domain/build/reports/jacoco/test/jacocoTestReport.xml'
2022-06-16T11:21:18.080+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
2022-06-16T11:21:18.080+0000 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Reading report '/home/jenkins/workspace/generated-pipelines/mobility-be-matching/matcher-service/matcher-ci/code-quality/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml'

Regards,
Shabbir

Hello @sbrakl,

Sorry for such a late reply. I have a few questions for you to be able to investigate your issue:

  • Have you checked JaCoCo report itself? Do you see coverage information there?
  • Could you please clarify if you’re using java-like directory structure (package == directory structure). For example a class com.example.Test is located in src/main/kotlin/com/example/Test.kt file.

If the answer to the second question is “no”, then this is not yet supported in SonarQube. However here is the ticket to fix it:
https://sonarsource.atlassian.net/browse/JACOCO-16

Regards,
Margarita