19
votes

I'm trying to do Sonar Setup with Jacoco for Kotlin to generate Code Coverage report but it's not showing any code coverage. While checking Sonar Console it showing following error. Anyone has faced this issue before, any suggestion what could be miss.

Meta info

plugin using sonarqube version "2.6.1"

gradleVersion = '3.0.1'

kotlinVersion = '1.2.21'

Sonarqube version = Version 6.7.1 (build 35068) - LGPL v3

Frustrating part is, my setup project generating blank code coverage report :(. PFA.

enter image description here

Edit : Please find project structure snap.

I'm adding sonar & Jacoco gradle file setup I'm using to generate sonar-matrix report.

enter image description here

Here is sonar.gradle file:

sonarqube {

    properties {
        property "sonar.projectKey", "jacoco.sonar.test"
        property "sonar.projectName", "Sonar Jacoco Test"
        property "sonar.projectVersion", "1.1"

        property "sonar.java.source", "7"

        property "sonar.android.lint.report", "build/outputs/lint-results.xml"
        property "sonar.java.binaries", "build/tmp/kotlin-classes"
        property "sonar.java.test.binaries", "build/intermediates/classes/test/,build/tmp/kotlin-classes/devDebugUnitTest"
        property "sonar.tests","src/test/java"
        property "sonar.sources","src/main/java"
        property "sonar.java.coveragePlugin", "jacoco"
        property "sonar.jacoco.reportPaths","build/jacoco/testDevDebugUnitTest.exec"
        property "sonar.junit.reportsPath","build/test-results/testDevDebugUnitTest"
    }
}

and here is jacoco.gradle file

apply plugin: 'jacoco'

jacoco {
    toolVersion = "0.7.9"
    reportsDir = file("${project.projectDir}/app/build/reports")
}

task jacocoTestReport(type: JacocoReport, dependsOn: "app:testDevDebugUnitTest") {
    group = "Reporting"

    reports {
        xml.enabled = true
        html.enabled = true
    }

    def fileFilter = ['**/R.class',
                      '**/R$*.class',
                      '**/BuildConfig.*',
                      '**/*$ViewInjector*.*',
                      '**/*$ViewBinder*.*',
                      '**/*$MembersInjector*.*',
                      '**/Manifest*.*',
                      '**/*Test*.*',
                      'android/**/*.*']

    classDirectories = fileTree(
            dir: "${project.projectDir}/app/build/intermediates/classes/dev",
            excludes: fileFilter
        ) + fileTree(
            dir: "${project.projectDir}/app/build/tmp/kotlin-classes/devDebug",
            excludes: fileFilter
        )

    // sources
    sourceDirectories = files(["${project.projectDir}/app/src/main/java"])
    executionData = files("${project.projectDir}/app/build/jacoco/testDevDebugUnitTest.exec")
}

Following gradle commands I'm using to generate Jacobo report & then soar report.

./gradlew clean jacocoTestReport sonarqube

I observed following I'm getting, must be issue some path.

Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?

I'm sorry, if this is looking bit length; but this is best I found to summaries in one place. Please also note I tried similar setup with Java class instead Kotlin it's generating report with code coverage.

2
Could you edit your question to include your SonarQube version, please?G. Ann - SonarSource Team
please check the footer of your SonarQube page and add the version you find there. I suspect what you've labeled as your SonarQube version is actually the version of your scanner.G. Ann - SonarSource Team
what version of SonarJava are you using? and which version on Jacoco reports are you generating? SonarJava 5.1 adds jacoco 8.0 support - i am not sure what version you are generating, but this could be maybe related?Simon Schrottner
I'm using: SQube: 7.0, SRunner: 3.0.3.778. Jacoco version I have not mentioned explicit and it should be use latest one(i.e. jacoco-0.8.0).CoDe
Where is kotlin source files located?Andrew

2 Answers

0
votes

If you're using the android test orchestrator this is likely the problem.

I had the same issue today and after disabling the android test orchestrator the coverage is working again.

Bug report: https://issuetracker.google.com/issues/72758547

I'm not sure how Android Kotlin builds are configured, but in my Android Java build.gradle I had to comment out the test orchestrator like so:

android {
...
    testOptions {
        // temporarily disable the orchestrator as this breaks coverage: https://issuetracker.google.com/issues/72758547
        //execution 'ANDROID_TEST_ORCHESTRATOR'
    ...
    }
}
0
votes

There are few things you need to do to make it work for kotlin.

  • Ensure your sonarqube > 7.5
  • If your sonarqube ver < 7.5, have the admin install sonar-jacoco plugin. Check the plugin compatibility version if sonarqube < 5.5.
plugins {
    id "jacoco"
    id "org.sonarqube" version "2.7.1"
}

Follow this url: https://community.sonarsource.com/t/coverage-test-data-importing-jacoco-coverage-report-in-xml-format/12151

Add properties in your build.gradle for it to search for jacoco results.

property 'sonar.coverage.jacoco.xmlReportPaths', "${buildDir}/reports/jacoco/test/jacocoTestReport.xml"

Follow this url for properties: https://docs.sonarqube.org/7.5/analysis/analysis-parameters/