gradle-kotlin-dsl - 如何将项目中的 sourceSet 转换为 kotlin kts

标签 gradle-kotlin-dsl

我有一个多模块 gradle 项目。我正在将所有 build.gradle 配置文件转换为 Kotlin kts。

但是我找不到如何将下面的代码转换为 kotlin kts。

我尝试将groovy代码放入kts中并检查了文档,但我找不到任何东西。

    testCompile project(":entities").sourceSets.test.output

最佳答案

经过一番调查,我发现这方面的语法最近发生了变化。

我尝试了一些变体,并发现:

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/

相关文章:

gradle - 在 gradle 依赖中,为什么 API 配置会丢弃所有传递依赖?

gradle - 如何使用 Gradle 和 Kotlin DSL 创建额外的 Kotlin SourceSet

gradle - 如何在Gradle插件中添加对配置的依赖

Gradle子项目条件插件配置与gradle kotlin dsl

gradle - 将凭证放在哪里

android - Unresolved reference : Libraries - buildSrc

kotlin - 如何将初始化脚本中定义的类导入build.gradle?

gradle - 如何从Gradle Kotlin DSL表达式中访问项目版本?

gradle - 使用 Gradle 构建带有 Kotlin-DSL 依赖项的 jar

kotlin - Gradle的初学者问题