How to configure/upload coverage reports to SonarCloud.io?

Context

I am trying to push pregenerated code coverage to sonarcloud.io for a multi-modules Android project. Gradle 6.3 is used in the project.

Setup

I am right now trying to use com.dicedmelon.gradle:jacoco-android:0.1.4 and org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.8 (not committed/pushed yet).
After running the jacocoTestReport task I can find a jacoco.xml file being generated in app/build/jacoco.

For the SonarQube scanner I configured the following:

sonarqube {
    properties {
        property "sonar.host.url", "https://sonarcloud.io"
        property "sonar.organization", "eventfahrplan"
        property "sonar.projectKey", "eventfahrplan"
        property "sonar.projectName", "EventFahrplan"
        property "sonar.projectVersion", APP_VERSION
        property "sonar.coverage.jacoco.xmlReportPaths", "app/build/jacoco/jacoco.xml"
        property "sonar.junit.reportsPath", "app/build/test-results/*/TEST-*.xml"
    }
}

Running sonarqube

When I run the sonarqube task then the following error is output:

$ ./gradlew sonarqube
Task :app:sonarqube
No coverage report can be found with sonar.coverage.jacoco.xmlReportPaths=‘app/build/jacoco/jacoco.xml’. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml

Questions

  1. Am I configuring the correct path for xmlReportPaths?
  2. Are these the correct plugins to use?
  3. How can I generate a coverage report for all modules of my project?

Related

Hi @tobiaspreuss,

Maybe dumb question but have you check that the file is where it has been set in the property ? Is this file with valid data inside ?

You can comma-separate values, so if you have one file per module, you can pass them in the same property.

Mickaël

have you check that the file is where it has been set in the property ?

Yes. I mentioned this up there.

Is this file with valid data inside ?

How do I know?

You can comma-separate values, so if you have one file per module, you can pass them in the same property.

I guess I have to do this because wildcards are not supported, right?

Hello,
I know it has been already a few weeks, do you still face the issue?

Still, here are my attempt to answer your questions:

  1. Are these the correct plugins to use?

From a Sonar tools perspective, it seems that you have everything needed. Concerning the rest, I’m afraid I don’t have enough knowledge to help you there.

  1. How can I generate a coverage report for all modules of my project?

SonarCloud is only importing pre-generated reports, we are not generating them. I don’t think it is possible, but you may want to double-check.

  1. Am I configuring the correct path for xmlReportPaths ?

Either the report is not available at analysis time, or the path is not correct. Typically, I would go for "build/jacoco/jacoco.xml", but of course, it depends on the structure of the project.

I hope this helps.