Rob Elliot
08/22/2022, 1:47 PMcompileGroovy
to see the Kotlin classes though. Could anyone give me some pointers?build.groovy
config I used to get Kotlin depending on Groovy:
tasks.named('compileGroovy') {
// Groovy only needs the declared dependencies
// (and not longer the output of compileJava)
classpath = sourceSets.main.compileClasspath
}
tasks.named('compileKotlin') {
// Kotlin also depends on the result of Groovy compilation
// (which automatically makes it depend of compileGroovy)
classpath += files(sourceSets.main.groovy.classesDirectory)
}
tasks.named('compileTestGroovy') {
// Groovy only needs the declared dependencies
// (and not longer the output of compileJava)
classpath = sourceSets.test.compileClasspath
}
tasks.named('compileTestKotlin') {
// Kotlin also depends on the result of Groovy compilation
// (which automatically makes it depend of compileGroovy)
classpath += files(sourceSets.test.groovy.classesDirectory)
}
August Lilleaas
08/22/2022, 1:51 PMRob Elliot
08/22/2022, 1:53 PMtasks.named('compileGroovy') {
classpath = [
sourceSets.main.compileClasspath,
sourceSets.main.kotlin.classesDirectory
]
}
but classesDirectory
is not a property of sourceSets.main.kotlin
.Vampire
08/22/2022, 1:59 PMRob Elliot
08/22/2022, 2:15 PMtasks.named('compileKotlin') {
classpath = sourceSets.main.compileClasspath
}
tasks.named('compileGroovy') {
classpath += files(sourceSets.main.kotlin.classesDirectory)
}
but sourceSets.main.kotlin.classesDirectory
doesn't seem to exist.Vampire
08/22/2022, 2:17 PM.java.
instead of .kotlin.
.
Iirc, that's the way to go.Rob Elliot
08/22/2022, 2:30 PMcompileGroovy
is still reporting unable to resolve class XXX
for all my Kotlin classes. A build/classes/kotlin
directory exists with my compiled Kotlin classes, so I guess compileKotlin
does have its own independent output? Or would it have added it to sourceSets.main.java.classesDirectory
?
I do find it hard to navigate the Gradle model to work out what to do in these circumstances. Unfortunately googling anything involving the words gradle, groovy and kotlin inevitably brings up reams of results about the gradle DSL.tasks.named('compileGroovy') {
classpath += files(tasks.compileKotlin.destinationDir)
}
tasks.compileKotlin.destinationDir
.tasks.named('compileGroovy') {
classpath += files(tasks.compileKotlin.destinationDirectory)
}
tasks.named('compileTestGroovy') {
classpath += files(tasks.compileTestKotlin.destinationDirectory)
}
If this is wrong™ please let me know.