简体   繁体   中英

Sonar Jacoco for Kotlin Setup not generating code coverage

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

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

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM