How to configure sonar.coverage.jacoco.xmlReportPaths for JaCoCo/SonarQube?

We can generate Jacoco reports in XML format by specifying xml.enabled value to true and providing destination path in the reports section.

plugins {
      id "org.sonarqube" version "2.8"
}
    jacocoTestReport {
        group = "Reporting"
        reports {
            xml.enabled true
            csv.enabled false
            //to create coverage report in html
            html.destination file("${buildDir}/reports/coverage")
            //for XML
            xml.destination file("${buildDir}/reports/jacoco.xml")
        }
    }

The SonarQube properties can be also configured through the build.gradle file. As sonar.jacoco.reportPath and sonar.jacoco.reportPaths are deprecated properties from the sonar version of 7.7 which should be replaced with sonar.coverage.jacoco.xmlReportPaths.

  • Configuring the Sonarqube properties through the build.gradle
sonarqube {
    properties {
        property 'sonar.projectName', 'MyExample Library'
        property 'sonar.projectKey', 'MyExampleLib'
        property 'sonar.core.codeCoveragePlugin', 'jacoco'
        property 'sonar.coverage.jacoco.xmlReportPaths', "${project.buildDir}/reports/jacoco.xml"
    }
}

  • If you wish to do that through sonar-project.properties then update the deprecated properties mentioned below to the suggested one.
sonar.jacoco.reportPath=build/reports/jacoco.xml

Finally, by executing gradle jacocoTestReport sonarqube command, the jacoco test report files such as ${project.buildDir}/reports/jacoco.xml and ${project.buildDir}/jacoco/test.exec will be generated for SonarQube.


It seems that your build is based on Gradle. It would be easier to use jacoco and sonarqube plugins in the gradle build

plugins {
    id "jacoco"
    id "org.sonarqube" version "2.8"
}

you don't need sonar-project.properties, analysis is configured from your build. You can customize default values in sonarqube configuration

// in build.gradle
sonarqube {
    properties {
        property "sonar.exclusions", "**/*Generated.java"
    }
}

To enable coverage you need to configure gradle to generate XML report

jacocoTestReport {
    reports {
        xml.enabled true
    }
}

And then run with gradle build jacocoTestReport sonarqube. More details can be found here and in SonarScanner for Gradle doc