Sonarqube jacoco coverage path not picking up even after setting with Android

Android Gradle config:

  • SonarQube (android, via plugin - id “org.sonarqube” version “3.3”)
  • SonarServer locally run (sonarqube-9.4.0.54424 windows)
  • Jacoco 0.8.7
  • Sonarqube property not picking up jacoco generated XML report path

Till now,

basically, I have multi-module app
Conda

  • app
  • data

In project-level build.gradle, applied jacoco.gradle to its all sub-modules

subprojects { Project module →
if (module.name == ‘app’) {
apply plugin: ‘com.android.application’
} else {
apply plugin: ‘com.android.library’
}
apply from: ‘…/jacoco.gradle’
}

and here’s my a snippet of jacoco.gradle

FileTree getJacocoClassDirs(List fileFilter) {
    def classDirs = files().asFileTree
    classDirs += fileTree(dir: "$project.rootDir/$project.name/build/intermediates/javac/debug", excludes: fileFilter)
    classDirs += fileTree(dir: "$project.rootDir/$project.name/build/tmp/kotlin-classes/debug", excludes: fileFilter)
    return classDirs
}

task generateJacocoTestReport(type: JacocoReport) {
    dependsOn ":$project.name:testDebugUnitTest"
    group = 'Reporting'
    description = "Generate Jacoco coverage reports for the debug build. Only unit tests."
    executionData.from = files(executionData.findAll { it.exists() })
    additionalSourceDirs.from = files("$project.rootDir/$project.name/src/main/java")
    sourceDirectories.from = files("$project.rootDir/$project.name/src/main/java")
    classDirectories.from = getJacocoClassDirs(fileFilter)
    executionData.from = fileTree(dir: project.rootDir, includes: ["$project.name/build/jacoco/testDebugUnitTest.exec"])
    reports {
        html.enabled = true
        xml.enabled = true
        csv.enabled = false
    }
}

So, jacoco correctly generates two different jacoco reports as per my modules i.e. app and data and
location is “build/reports/jacoco/generateJacocoTestReport/generateJacocoTestReport.xml

so, in my sonarqube.gradle which is defined in project-level build.gradle

sonarqube {
    properties {
        property "sonar.language", "kotlin"
        property "sonar.sourceEncoding", "UTF-8"
        property "sonar.sources", "src/main/java"
        property "sonar.tests", "src/test/java"
        property "sonar.junit.reportPaths", "build/test-results/testDebugUnitTest"
        property "sonar.core.codeCoveragePlugin", "jacoco"
        property "sonar.coverage.jacoco.xmlReportPaths", 'build/reports/jacoco/generateJacocoTestReport/generateJacocoTestReport.xml'
        property "sonar.binaries", "build/intermediates/classes/debug, build/tmp/kotlin-classes/debug"
        property "sonar.java.binaries", "build/intermediates/classes/debug, build/tmp/kotlin-classes/debug"
        property "sonar.java.test.binaries", "build/intermediates/classes/test/, build/tmp/kotlin-classes/debugUnitTest"
    }

}

Now, when I execute ./gradlew sonarqube
I can see

> No coverage report can be found with sonar.coverage.jacoco.xmlReportPaths=‘build/reports/jacoco/generateJacocoTestReport/generateJacocoTestReport.xml’. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.x
> ml

you can clearly see the path is a valid location.

I am not sure what I am doing wrong here,
Any guidance will be greatly appreciated.

Hi,

Welcome to the community!

Most of those properties should be picked up automatically from the Gradle context. Can you try commenting out or removing all your properties & re-analyzing?

 
Ann