如何为基于 Kotlin 的 Gradle 脚本中的测试启用“--enable-preview”?我尝试了所有我可以在网上找到的东西,https://stackoverflow.com/a/61849770/226895是最接近正确答案的。
我仍然在:test
任务中收到以下错误
org.gradle.api.internal.tasks.testing.TestSuiteExecutionException: Could not execute test class 'com.blabla.playground.AppTest'.
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:53)
Caused by: java.lang.UnsupportedClassVersionError: Preview features are not enabled for com/blabla/playground/AppTest (class file version 58.65535). Try running with '--enable-preview'
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
按脚本是
plugins {
java
application
}
repositories {
jcenter()
}
dependencies {
implementation("com.google.guava:guava:28.2-jre")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.0")
}
application {
mainClassName = "com.blabla.playground.App"
}
java {
sourceCompatibility = JavaVersion.VERSION_14
targetCompatibility = JavaVersion.VERSION_14
}
tasks {
withType<Test>().all {
allJvmArgs.add("--enable-preview")
testLogging.showStandardStreams = true
testLogging.showExceptions = true
useJUnitPlatform {
}
}
withType<JavaExec>().all {
jvmArgs!!.add("--enable-preview")
}
withType<Wrapper>().all {
gradleVersion = "6.4.1"
distributionType = Wrapper.DistributionType.BIN
}
withType(JavaCompile::class.java).all {
options.compilerArgs.addAll(listOf("--enable-preview", "-Xlint:preview"))
}
jar {
manifest {
attributes("Main-Class" to "com.blabla.playground.App")
}
}
}
我错过了什么?