'Gradle 6+ : compile groovy before kotlin

I'm working on a project combining groovy and kotlin. My Kotlin classes require objects from groovy part, how can i make gradle compile groovy before kotlin ?

I'm using Gradle 6.3 with kotlin-dsl

I've tried several solutions : srcsets order, tasks order, ... Nothing seems to work

Any idea ?



Solution 1:[1]

Thanks to tim_yates ! (why this documentation doesn't come out on google ?)

Here is the adaptation of documentation for kotlin & groovy

tasks.named<AbstractCompile>("compileGroovy") {
    // Groovy only needs the declared dependencies
    // (and not longer the output of compileJava)
    classpath = sourceSets.main.get().compileClasspath
}

tasks.named<AbstractCompile>("compileKotlin") {
    // Java also depends on the result of Groovy compilation
    // (which automatically makes it depend of compileGroovy)
    classpath += files(sourceSets.main.get().withConvention(GroovySourceSet::class) { groovy }.classesDirectory)
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jared Burrows