Sonarqube does not report full Jacoco coverage

Hi there.

I found that the gradle sonar plugin (or sonar itself) does not report the aggregated Jacoco coverage correctly.

In a multi-module project where one sub project covers the others method, it’s coverage is not taken correctly from the Jacoco results.

The Jacoco XML and HTML reports show the correct coverage of 100%, but sonarqube reports only 80%.

I have prepared a small project which demonstrates the problem:

https://github.com/thackel/sonar-aggregated-coverage-test

It was tested with the following software
Gradle sonarqube plugin 4.0.0.2929 and also **the latest one (4.4.1.3373) ** (the repository contains the first of the 4.x branch).
Sonarqube 9.5 developer, Sonarqube 9.9 community and Sonarqube 10.x (using the docker images).
Several permutations of sonarqube and plugin version have been tested.

Note that the computation used by Jacoco and SonarQube to compute “coverage” are different. In Jacoco, you are likely seeing the “line coverage”. In SonarQube, the “coverage” value is a weighted average of line coverage and condition coverage. I’ll let a sonarsourcer cite the link to the exact computation.

Thanks for kicking off the discussion @David_Karr! And thanks @thomas-h for the reproducer.

I think the issue here isn’t about how coverage is computed, but how the reports are being passed to each module.

I was able to get 100% coverage by moving the sonar.coverage.jacoco.xmlReportPaths configuration into a block that applies to all modules.

sonar {
    properties {
        property 'sonar.sourceEncoding', 'UTF-8'
    }
}

subprojects {
    sonar {
        properties {
            property 'sonar.coverage.jacoco.xmlReportPaths', "${project.rootDir}/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml"

        }
    }
}