-->

Sonar Jacoco for Kotlin Setup not generating code

2019-03-25 02:56发布

问题:

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.

Edit : Please find project structure snap.

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

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 summarise on one place. Please also note I tried similar setup with Java class instead kotlin it's generating report with code coverage.

回答1:

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'
    ...
    }
}