我正在使用gradle与kotlin一起工作。现在,我需要改进代码,并且将sonarqube与jacoco一起使用。但我的覆盖率始终为0.0%。我的gradle:
plugins {
kotlin("jvm") version "1.3.70"
id("org.sonarqube") version "2.8"
jacoco
`maven-publish`
}
repositories {
mavenLocal()
jcenter()
}
sonarqube {
properties {
property("sonar.host.url", "http://localhost:9000")
property("sonar.language", "kotlin")
property("sonar.sourceEncoding", "UTF-8")
property("sonar.projectName", "Commons.Pulsar")
property("sonar.projectKey", "Aries.kt")
property("sonar.projectVersion", "0.0.1")
property("sonar.sources", "src/main/kotlin/")
property("sonar.junit.reportPaths", "src/test/kotlin/")
property("sonar.login", "admin")
property("sonar.password", "admin")
property("sonar.coverage.jacoco.xmlReportPaths", "build/jacoco/test/jacocoTestReport.xml")
}
}
java {
withJavadocJar()
withSourcesJar()
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
}
}
}
tasks {
test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
}
jacocoTestReport {
reports {
xml.isEnabled = true
}
}
compileKotlin {
kotlinOptions.jvmTarget = "11"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "11"
}
}
但是我注意到没有创建jacocoTestReport.xml。没有创建xml。有人可以帮忙吗?
您无需指定sonar.coverage.jacoco.xmlReportPaths
属性,只需要确保在jacocoTestReport
目标之前执行任务sonarqube
。 sonarqube gradle插件足够聪明,可以根据jacoco报告检测配置。作为示例,我链接了Junit Pioneer build configuration,我们也这样做。
通常来说,sonarqube gradle插件功能强大而安静,如果您利用gradle的所有构建,您的sonarqube块只需看起来像这样
sonarqube {
properties {
property("sonar.host.url", "http://localhost:9000")
property("sonar.sourceEncoding", "UTF-8")
property("sonar.login", "admin")
property("sonar.password", "admin")
}
}
如sonarqube documentation中所述,它将从gradle配置中检测到其余的内容>