【发布时间】:2022-12-09 17:45:36
【问题描述】:
我在 buildSrc/src/main/kotlin/foo.bar.kts 中有一个 Gradle 插件,我正在尝试修改任务,但这些修改失败了。如果我删除任务修改部分,其余部分,即设置存储库,就可以正常工作。
我想我缺少语法 how to modify tasks in the module that imports this plugin。
buildSrc/src/main/kotlin/foo.bar.kts:
repositories {
mavenCentral()
}
tasks.test {
useJUnitPlatform()
}
tasks.withType<KotlinCompile>() {
kotlinOptions.jvmTarget = "11"
}
在我的build.gradle.kts中使用插件
plugins {
id("foo.bar")
}
./gradlew clean build 生成的错误
> Task :buildSrc:compileKotlin FAILED
e: /some/path/buildSrc/src/main/kotlin/foo.bar.gradle.kts: (8, 7): Unresolved reference: test
e: /some/path/buildSrc/src/main/kotlin/foo.bar.gradle.kts: (9, 5): Unresolved reference: useJUnitPlatform
e: /some/path/buildSrc/src/main/kotlin/foo.bar.gradle.kts: (12, 16): Unresolved reference: KotlinCompile
e: /some/path/buildSrc/src/main/kotlin/foo.bar.gradle.kts: (12, 33): Type mismatch: inferred type is () -> Unit but Class<TypeVariable(S)!> was expected
e: /some/path/buildSrc/src/main/kotlin/foo.bar.gradle.kts: (13, 5): Unresolved reference: kotlinOptions
e: /some/path/code/buildSrc/src/main/kotlin/foo.bar.gradle.kts: (13, 19): Variable expected
【问题讨论】:
标签: kotlin gradle gradle-kotlin-dsl