我正在使用gradle创建一个kotlin跨平台项目(Android + JVM11 + JFX),现在我想使用JaCoCo。
这是我的build.gradle.kts:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("maven-publish")
kotlin("multiplatform")
jacoco
}
val nexusUsername: String by project
val nexusPassword: String by project
val nexusUrl: String by project
val isCI: String by project
publishing {
repositories {
maven {
if (isCI == "true") {
url = uri("/opt/repo")
} else {
credentials {
username = nexusUsername
password = nexusPassword
}
url = uri(nexusUrl)
}
}
}
}
kotlin {
jvm {
val main by compilations.getting {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
}
}
val compileTestKotlinJvm: KotlinCompile by tasks
compileTestKotlinJvm.kotlinOptions.jvmTarget = JavaVersion.VERSION_11.toString()
tasks.withType<Test> {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
//ignoreFailures = true
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(kotlin("stdlib-common"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
implementation("org.junit.jupiter:junit-jupiter-api:5.6.0")
implementation("org.junit.jupiter:junit-jupiter-params:5.6.0")
runtimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.0")
}
}
val jvmMain by getting {
dependencies {
implementation(kotlin("stdlib-jdk8"))
}
}
val jvmTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(kotlin("test-junit"))
implementation("org.junit.jupiter:junit-jupiter-api:5.6.0")
implementation("org.junit.jupiter:junit-jupiter-params:5.6.0")
runtimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.0")
}
}
}
}
jacoco {
toolVersion = "0.8.5"
}
//tasks.jacocoTestReport {
tasks.withType<JacocoReport> {
dependsOn("jvmTest")
reports {
xml.isEnabled = true
csv.isEnabled = false
html.isEnabled = true
}
}
实际上,Android代码不在我的优先级之内
我得到那个错误:
08:52:23: Executing tasks 'clean cleanAllTests build jacocoTestReport'...
> Configure project :common
Kotlin Multiplatform Projects are an experimental feature.
FAILURE: Build failed with an exception.
* What went wrong:
Task 'jacocoTestReport' not found in project ':common'.
* Try:
Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 633ms
08:52:23: Tasks execution finished 'clean cleanAllTests build jacocoTestReport'.
完整的项目在这里:https://gitlab.com/deglans/mandalaproject和此处:https://sonarcloud.io/dashboard?id=deglans_mandalaproject
我正在该分支机构上:https://gitlab.com/deglans/mandalaproject/-/tree/clean-update-and-test。