Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make compileKotlin dependsOn compileJava in gradle

Tags:

gradle

kotlin

While using kotlin with gradle, compileKotlin executes before compileJava. I need to execute compileJava before compileKotlin. I tried compileKotlin.dependsOn(compileJava) but it gives the Circular dependency build failure.

Circular dependency build failure

I also tried

compileJava.dependsOn = compileJava.taskDependencies.values - compileKotlin

But, it still executes compileKotlin before compileJava.

How can I execute compileJava before compileKotlin?

like image 568
TheKojuEffect Avatar asked Dec 29 '17 11:12

TheKojuEffect


1 Answers

I faced the same problem in a spike test with gradle, Java, Kotlin, Scala and Groovy all together - not a real scenario, I recognize it!, but noticed that (by default, i.e. without any explicit configuration)

  1. compileJava dependsOn compileKotlin
  2. compileScala dependsOn compileJava
  3. compileGroovy dependsOn compileJava

This limits my choices about the order which I can build my sources in: Java compilation can't happen before Kotlin compilation, as you told, and by converse Groovy and Scala compilation can't happen before Java compilation (which was my initial goal).

My idea is that the simplest wat to get the desired result is to split my source code into four different projects, setting up a multi-module project: this way I can move the problem from defining task dependencies (which as seen I can't control) to defining module dependencies (which I can control very simple through plan dependency management using something like compile project(':my-dependend-on-project') in my dependant project's build.gradle).

This is a very old question, so I suppose you already found a solution; anyway, I'm interested in your opinion about my conclusions about this topic.

like image 163
Pietro Martinelli Avatar answered Nov 08 '22 10:11

Pietro Martinelli