Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 456
yodamad Avatar asked Oct 23 '25 02:10

yodamad


1 Answers

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)
}
like image 98
yodamad Avatar answered Oct 25 '25 00:10

yodamad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!