添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
叛逆的镜子  ·  sklearn ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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.

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 Feb 14, 2018 at 13:33 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 Feb 21, 2018 at 9:47 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 Feb 21, 2018 at 9:55

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'
  • 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/

    Thank you for reply. I have not same setup now to try this out. But will it be possible for you to create and share repo sample so other can refer and that would be great help. – CoDe Jun 2, 2020 at 10:04

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.