Search code examples
jenkinssonarqubejacoco

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


SonarQube 7.7 shows the following warning for a Java project analysis:

Property 'sonar.jacoco.reportPath' is deprecated (JaCoCo binary format). 'sonar.coverage.jacoco.xmlReportPaths' should be used instead (JaCoCo XML format).

The Gradle based project is configured via sonar-project.properties as follows:

sonar.projectKey=MyExampleLib
sonar.projectName=MyExample Library
sonar.sources=src/main/java
sonar.jacoco.reportPath=build/jacoco/test.exec
sonar.junit.reportsPath=build/test-results/test
sonar.java.test.binaries=build/classes/test
sonar.java.binaries=build/classes/java/main
sonar.binaries=build/classes
sonar.projectVersion=$libVersion

The SonarQube server URL is injected via (otherwise you end up with a "localhost:9000" error):

Prepare SonarQube Scanner environment

The SonarQube analysis is triggered via Jenkins and the JaCoCo plugin v.3.0.4 with the following Job configuration:

JaCoCo configuration

I read that a report.xml is picked up by xmlReportPaths. How can I generate it?

Related


Solution

  • 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