Reputation: 105
I have a multi module gradle project. I'm converting all build.gradle configuration files to Kotlin kts.
But I can't find how to convert this code below to kotlin kts.
I tried to place groovy code inside kts and checked the documentation, but I could't find anything.
testCompile project(":entities").sourceSets.test.output
Upvotes: 2
Views: 1657
Reputation: 122
This also works for me.
dependencies {
testImplementation(project(":entities").dependencyProject.sourceSets["test"].output)
}
Upvotes: 2
Reputation: 156
After some investigation, I found that the syntax in this area has changed recently.
This gives some history:
https://github.com/gradle/kotlin-dsl/issues/577
The Kotlin DSL 1.0-RC3 introduced some breaking changes:
https://github.com/gradle/kotlin-dsl/releases/tag/v1.0-RC3
the sourceSets collection does still exist on the project: https://docs.gradle.org/5.0/dsl/org.gradle.api.Project.html#org.gradle.api.Project:sourceSets)
I tried a few variants, and discovered that:
dependencies {
testImplementation(project(":entities").sourceSets["test"].output)
}
results in
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
But the following works just fine, as long as the Java plugin is enabled:
val entityTests: SourceSetOutput = project(":entities").sourceSets["test"].output
dependencies {
testImplementation(entityTests)
}
Upvotes: 2