【发布时间】:2020-07-18 17:46:33
【问题描述】:
代码覆盖率在仪表板上显示为 0%
build.gradle 文件
plugins {
id "org.sonarqube" version "2.8"
id "java"
id "idea"
id "jacoco"
}
jacoco {
toolVersion = "0.8.5"
}
jacocoTestReport {
reports {
html.enabled true
xml.enabled true
xml.destination file("${buildDir}/reports/jacoco.xml")
}
}
plugins.withType(JacocoPlugin) {
tasks["test"].finalizedBy 'jacocoTestReport'
}
sonarqube {
properties {
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.host.url", "http://169.254.1.100:9000"
property "sonar.coverage.jacoco.xmlReportPath", "${buildDir}/reports/jacoco.xml"
}
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
// https://mvnrepository.com/artifact/junit/junit
testCompile 'junit:junit:4.12'
}
check.dependsOn jacocoTestReport
运行这个命令
./gradlew build jacocoTestReport sonarqube
生成的 JacocoTestReport 具有正确的代码覆盖率
Sonarqube gradle 任务生成此日志
> Task :sonarqube
SonarScanner will require Java 11 to run starting in SonarQube 8.x
Property 'sonar.jacoco.reportPath' is no longer supported. Use JaCoCo's xml report and sonar-jacoco plugin.
Property 'sonar.jacoco.reportPaths' is no longer supported. Use JaCoCo's xml report and sonar-jacoco plugin.
google了半天,唯一真正解决这个问题的方法如下: Property 'sonar.jacoco.reportPath' is deprecated. Please use 'sonar.jacoco.reportPaths' instead
这个答案here解释了双重输出:
Property 'sonar.jacoco.reportPaths' is no longer supported. Use JaCoCo's xml report and sonar-jacoco plugin.
但是这似乎没有添加到 gradle 插件中,因为正在使用的插件是 2.8,是发布时的最新版本。
我有什么遗漏吗?
【问题讨论】:
-
你知道
sonar.coverage.jacoco.xmlReportPaths末尾缺少s吗? -
@SimonSchrottner 在文档中
Paths和Path都被接受,无论哪种方式我都尝试过,但它们都不起作用 -
如果你使用
sonar.coverage.jacoco.xmlReportPaths,你不需要sonar.jacoco.reportPaht(s),只要你使用sonar.coverage.jacoco.xmlReportPaths而不是sonar.coverage.jacoco.xmlReportPath-docs.sonarqube.org/latest/analysis/coverage
标签: java docker gradle sonarqube jacoco