Kotlin JaCoCo Code Coverage is Ignored

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarQube - 6.7.2
    SonarQube gradle plugin version - 3.0
    Jacoco gradle plugin version - 0.8.5

  • what are you trying to achieve
    We have a multi-module Kotlin Android project.
    We are using Azure DevOps for build management.
    SonarQube analyzes project and shows all metrics in the dashboard.
    But we couldn’t make Sonar import JaCoCo code coverage reports.
    It’s always zero percent.

Project SonarQube settings;
In Android project build.gradle (root) addded dependency for sonar gradle plugin
And applied sonar plugin only in root build.gradle with "apply plugin: ‘org.sonarqube’ "

Project JaCoCo settings;
It’s a bit long but we used this guide to setup jacoco in gradle
(‘moduleX’ parts are replaced with real modules in our application)
!!! We didn’t use SonarQube part, Sonar settings are given in build pipeline

At this part we could try JaCoCo in development machine and see that it generates reports in build folder
And main application module (app) has test coverage report for all modules

AzureDevops build pipeline;
1 - In build pipeline added Prepare Analysis Configuration like:

  • task: sonarsource.sonarqube.15B84CA1-B62F-4A2A-A403-89B77A063157.SonarQubePrepare@4
    displayName: ‘Prepare analysis on SonarQube’
    SonarQube: MySonarQubeServiceConnection
    scannerMode: Other
    extraProperties: |
    sonar.projectKey=(Build.Repository.Name) sonar.projectName=(Build.Repository.Name)
    sonar.branch.name = (Build.SourceBranchName) sonar.java.coveragePlugin=jacoco sonar.jacoco.reportPaths=(System.DefaultWorkingDirectory)\app\build\jacoco\testDebugUnitTest.exec

2 - Build gradle step is set like:

  • task: Gradle@2
    displayName: ‘Build Application’
    gradleWrapperFile: ‘gradlew’
    options: ‘–stacktrace’
    tasks: ‘build testDebugUnitTestCoverage’
    publishJUnitResults: ‘true’ (Publish to Azure Pipeline is checked)
    testResultsFiles: ‘**/build/test-results/testDebugUnitTest/TEST-*.xml’
    testRunTitle: ‘Android Unit Test’
    sonarQubeRunAnalysis: true
    sqGradlePluginVersionChoice: build
    checkStyleRunAnalysis: true
    pmdRunAnalysis: true

3 - And Publish Quality Gate Results:

  • task: sonarsource.sonarqube.291ed61f-1ee4-45d3-b1b0-bf822d9095ef.SonarQubePublish@4
    displayName: ‘Publish Quality Gate Result’
  • what have you tried so far to achieve this

With given settings in each commit application is tested and test results are generated
(we can see it in AzureDevOps server)
Code is analyzed in SonarQube for quality metrics
But code coverage result is not shown, zero

Gradle command run in build step:
gradlew.bat --stacktrace build testDebugUnitTestCoverage sonarqube -I D:…Long Path…\checkstyle.gradle -I D:…Long Path…\pmd.gradle

We tried
Changing “sonar.java.coveragePlugin=jacoco” to “sonar.core.codeCoveragePlugin=jacoco”
And without this parameter

Before giving .exec file, reportPaths parameter was taking xml report


But nothing changed. Everything worked same (project analyzed without coverage)

Can somebody help me with coverage report import?

Hi Gokmen, welcome to the SonarSource Community!

To start with, SonarQube 6.7.2 is quite old and no longer supported; we recommend you upgrade to at least the 7.9 LTS release or consider migrating all the way to 8.x since the final 8.x release will become the new LTS in a few months. Read our guidance on upgrading before getting started.

Since 6.7.x, we deprecated support for the old .exec JaCoCo report format in favor of XML reports - this took effect in the version of the JaCoCo report importer bundled with SonarQube 7.9 and is fully removed if you update to the latest. I’d recommend you upgrade, update all analyzers, and try this using XML format reports.

We have a number of guides for configuring and troubleshooting JaCoCo coverage issues in our Guides area:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.