我的gradle任务jacocoTestReport()正常工作,并生成jacocoTestReport.xml。它包含了Kotlin的预期覆盖范围。
但是,如果我使用SonarQube Scanner 4.0 Jenkins插件,它将无法发送Kotlin覆盖率报告的一部分。所以我在Sonarqube仪表板上找不到kotlin的覆盖范围。
我认为我的Analysis属性有问题,但找不到。
# required metadata
sonar.projectKey=aaaaa123
sonar.projectName=aaaaa123
sonar.projectVersion=${VERSION_MAJOR}.${VERSION_MINOR}
# disable sonar.language parameter to triggering multi-language analysis
#sonar.language=java
# path to test source directories
sonar.sources=mypicker/src/main/java
sonar.test.inclusions=mypicker/src/test/java
sonar.java.binaries=mypicker/build/intermediates/javac/debug,ext/mypicker/build/tmp/kotlin-classes/debug
#sonar.junit.reportPaths=mypicker/build/test-results/testDebugUnitTest
#sonar.jacoco.reportPaths=mypicker/build/jacoco/testDebugUnitTest.exec
sonar.coverage.jacoco.xmlReportPaths=mypicker/build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml
sonar.sourceEncoding=UTF-8
sonar.java.source=1.8
sonar.ws.timeout=300
sonar.findbugs.timeout=3600000
我最好的gradle任务代码是:
task jacocoTestReport(type: JacocoReport, dependsOn: 'testDebugUnitTest') {
reports {
xml.enabled = true
html.enabled = true
}
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
def javaDebugTree = fileTree(dir: "${buildDir}/intermediates/javac/debug", excludes: fileFilter)
def kotlinDebugTree = fileTree(dir: "${buildDir}/tmp/kotlin-classes/debug", excludes: fileFilter)
def mainSrc = "${project.projectDir}/src/main/java"
sourceDirectories.from = files([mainSrc])
classDirectories.from = files([javaDebugTree, kotlinDebugTree])
executionData.from = files("${buildDir}/jacoco/testDebugUnitTest.exec")
}
Sonarqube:6.7.5(内部版本38563) SonarQube扫描仪:4.0.0.1744