简体   繁体   中英

Sonarqube not picking up both Kotlin and Java Coverage gradle project

This is not an android project with mixed source Java and Kotlin. Eventhough many have had issues with coverage, kotlin and sonar. I didn't find one for this case.

Sonarqube is not picking up both Kotlin and Java Coverage generated by Jacoco:

  • Gradle 4.8
  • Java 1.8
  • Kotlin 1.3.50

It gets the Java one, but all of the Kotlin classes gets ignored. I have applied all required plugin in the gradle file:

allprojects {
    apply plugin: 'jacoco'
    apply plugin: 'java'
    apply plugin: 'org.sonarqube'
    apply plugin: 'kotlin'

   ...
}

First make sure your jacocoTestReport creates a xml report:

jacocoTestReport {
    reports {
        xml {
            enabled true
        }
        xml.destination "build/reports/jacocoTestReport.xml"
    }
} 

Then you will need to force those xml reports into sonar using the xmlReportPaths property in sonaqube for all projects.

You can see multiple paths here, that's in case you have multiple sub projects in your projects which also have mixed source Java / Kotlin.

sonarqube {
        properties {
            property "sonar.java.coveragePlugin", "jacoco"
            property("sonar.coverage.jacoco.xmlReportPaths", "../../build/reports/jacocoTestReport.xml,../build/reports/jacocoTestReport.xml")
        }
}

With that sonar will consider all the xml reports and generate the whole coverage.

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