Looks like what you need is:
compileGroovy.dependsOn = compileGroovy.taskDependencies.values - 'compileJava'
compileKotlin.dependsOn compileGroovy
compileKotlin.classpath += files(compileGroovy.destinationDir)
classes.dependsOn compileKotlin
-
taskDependencies.valuescontains aStringfor the task name - You need an explicit dependency for the
classestask, so it still runs before tests etc, becausecompileKotlindoesn’t output to the standard classes dir, it uses a post hook to copy from thekotlin-classesdirectory - Likewise, for Kotlin to compile against Groovy, you need to make the files output by the
compileGroovytask visible, without using the sourcesetoutput, as that’ll cause a circular dependency forclasses
It means that interop can only go one way, Kotlin -> Groovy, so you need to use reflection at the seams, or move your key wiring classes to Kotlin.
Incidentally, this is a handy extension for Groovy Closure interop:
fun <T> T.groovyClosure(function: () -> Unit) = object : Closure<Unit>(this) {
@Suppress("unused")
fun doCall() {
function()
}
}