使用 Karate Runner 和 Gradle Kotlin 调试空手道

问题描述 投票:0回答:1

由于 Gradle 默认其构建文件使用 Kotlin,而我从来都不是 Groovy 的粉丝,因此尝试使用开源

Karate Runner
(v1.2.5)进行调试。我尝试了几个版本的
karateExecute
任务,但似乎都不起作用。从空手道跑步者文档中我看到:

tasks.register<JavaExec>("karateExecute") {
    classpath = sourceSets.test.get().runtimeClasspath
    main.set(System.getProperty("mainClass"))
}

但是,运行时会返回以下错误

gradle init

 main.set(System.getProperty("mainClass"))
               ^ Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
                   public val SourceSetContainer.main: NamedDomainObjectProvider<SourceSet> defined in org.gradle.kotlin.dsl

打开 JDK 17

摇篮8.5

空手道1.4.1

build.gradle.kts:

plugins {
    `java`
    `maven-publish`
}

val karateVersion by extra("1.4.1")

repositories {
    mavenLocal()
    maven {
        url = uri("https://repo.maven.apache.org/maven2/")
    }
}

dependencies {
    implementation(libs.com.github.javafaker.javafaker){exclude ( "org.yaml")} 
    implementation (group= "org.yaml", name= "snakeyaml", version= "2.0")
    testImplementation("com.intuit.karate:karate-junit5:${karateVersion}")
}      

group = "com.mycompany"
version = "0.1"
description = "karatePoc"
java.sourceCompatibility = JavaVersion.VERSION_17

publishing {
    publications.create<MavenPublication>("maven") {
        from(components["java"])
    }
}

tasks.withType<JavaCompile>() {
    options.encoding = "UTF-8"
}

tasks.withType<Javadoc>() {
    options.encoding = "UTF-8"
}

sourceSets {
    test {
        resources {
            srcDir(file("src/test/java"))
            exclude("**/*.java")
        }
    }
}

tasks.test {
    useJUnitPlatform()
    systemProperty("karate.options", System.getProperty("karate.options"))
    systemProperty("karate.env", System.getProperty("karate.env"))
    outputs.upToDateWhen {false}
}

// task<JavaExec>("karateDebug") {
//     mainClass.set("com.intuit.karate.cli.Main")
//     classpath = sourceSets["test"].runtimeClasspath
// }

tasks.register<JavaExec>("karateExecute") {
    classpath = sourceSets.test.get().runtimeClasspath
    main.set(System.getProperty("mainClass"))
}
kotlin gradle karate
1个回答
0
投票

您正在使用已弃用的 API。请参阅

setMain()
中的
JavaExecSpec

您应该将该行替换为:

mainClass.set(System.getProperty("mainClass"))
© www.soinside.com 2019 - 2024. All rights reserved.