How to upload Test Coverage, JaCoCo, Multi Module, Android

Hi,

I need help about how to upload test coverage. Currently my configuration:

// build.gradle.kts (project root)
plugins {
  ...
  id("org.sonarqube") version "6.0.1.5171"
}

sonar {
  properties {
    property("sonar.projectKey", "waffiqaziz_BAZZ-Movies")
    property("sonar.organization", "waffiqaziz")
    property("sonar.host.url", "https://sonarcloud.io")
  }
}

buildscript {
  dependencies {
    classpath("org.bouncycastle:bcutil-jdk18on:1.79")
  }
}
# github workflow
  unit_test:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      actions: write
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Grant execute permission for Gradle wrapper
        run: chmod +x ./gradlew

      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          java-version: '17'
          distribution: 'temurin'
          cache: 'gradle'

      - name: Run debug unit tests
        run: ./gradlew testDebugUnitTest

      - name: Generate JaCoCo
        run: ./gradlew createDebugCombinedCoverageReport

      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574
        with:
          files: ${{ github.workspace }}/**/build/reports/jacoco/createDebugCombinedCoverageReport/createDebugCombinedCoverageReport.xml
          token: ${{ secrets.CODECOV_TOKEN }}
      
      - name: Upload coverage reports to Codacy
        uses: codacy/codacy-coverage-reporter-action@55c3b57cb3bb6833c8c1a6614fee4cebb140de2d
        with:
          project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
          coverage-reports: ${{ github.workspace }}/**/build/reports/jacoco/createDebugCombinedCoverageReport/createDebugCombinedCoverageReport.xml

      - name: Upload test results to Codecov
        if: ${{ !cancelled() }}
        uses: codecov/test-results-action@f2dba722c67b86c6caa034178c6e4d35335f6706
        with:
          token: ${{ secrets.CODECOV_TOKEN }}

      - name: Cache SonarCloud packages
        uses: actions/cache@v4
        with:
          path: ~/.sonar/cache
          key: ${{ runner.os }}-sonar
          restore-keys: ${{ runner.os }}-sonar

      - name: SonarCloud Scan
        uses: sonarsource/sonarqube-scan-action@aa494459d7c39c106cc77b166de8b4250a32bb97
        env:
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 
        with:
          args: >
            -Dsonar.projectKey=waffiqaziz_BAZZ-Movies
            -Dsonar.organization=waffiqaziz
            -Dsonar.coverage.jacoco.xmlReportPaths=${{ github.workspace }}/**/build/reports/jacoco/createDebugCombinedCoverageReport/createDebugCombinedCoverageReport.xml
            -Dsonar.java.binaries=${{ github.workspace }}/**/build/intermediates/javac/debug/classes
            -Dsonar.kotlin.binaries=${{ github.workspace }}/**/build/tmp/kotlin-classes/debug

But it doesn work, my coverage still show 0%. Here my PR

Thank you!

Hi,

You’ve provided an absolute path here. Per the docs,

Unless otherwise specified, these properties require values that are relative to the project root.

So I would try something like this:
-Dsonar.coverage.jacoco.xmlReportPaths=build/reports/jacoco/createDebugCombinedCoverageReport/createDebugCombinedCoverageReport.xml

 
HTH,
Ann

I use this

-Dsonar.coverage.jacoco.xmlReportPaths=${{ github.workspace }}/**/build/reports/jacoco/createDebugCombinedCoverageReport/createDebugCombinedCoverageReport.xml

because it is a relative path for my jacoco files for each module, and for other runners, it actually works.


Anyway, I’ve tried your suggestion, to use

-Dsonar.coverage.jacoco.xmlReportPaths=build/reports/jacoco/createDebugCombinedCoverageReport/createDebugCombinedCoverageReport.xml

but still return 0%. Here my runner and still on same pull request.

Hi,

Well, the log’s pretty clear:

15:40:15.693 WARN  No coverage report can be found with sonar.coverage.jacoco.xmlReportPaths='build/reports/jacoco/createDebugCombinedCoverageReport/createDebugCombinedCoverageReport.xml'. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
15:40:15.694 INFO  No report imported, no coverage information will be imported by JaCoCo XML Report Importer

You need to figure out where the JaCoCo report is being output to and point analysis to that location for it.

 
HTH,
Ann