我有一个多模块 gradle 项目。我正在将所有 build.gradle 配置文件转换为 Kotlin kts。
但是我找不到如何将下面的代码转换为 kotlin kts。
我尝试将groovy代码放入kts中并检查了文档,但我找不到任何东西。
testCompile project(":entities").sourceSets.test.output
最佳答案
经过一番调查,我发现这方面的语法最近发生了变化。
Kotlin DSL 1.0-RC3 引入了一些重大更改:
https://github.com/gradle/kotlin-dsl/releases/tag/v1.0-RC3sourceSets 集合仍然存在于项目中:https://docs.gradle.org/5.0/dsl/org.gradle.api.Project.html#org.gradle.api.Project:sourceSets )
- 该集合可以通过同行项目交叉引用
我尝试了一些变体,并发现:
dependencies {
testImplementation(project(":entities").sourceSets["test"].output)
}
结果
testImplementation(project(":entities").sourceSets["test"].output)
^ Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public val Project.sourceSets: SourceSetContainer defined in org.gradle.kotlin.dsl
但是只要启用了 Java 插件,以下操作就可以正常工作:
val entityTests: SourceSetOutput = project(":entities").sourceSets["test"].output
dependencies {
testImplementation(entityTests)
}
关于gradle-kotlin-dsl - 如何将项目中的 sourceSet 转换为 kotlin kts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56297459/