Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile Groovy and Kotlin?

Tags:

I'm working on a small project with Groovy and Kotlin, and my Kotlin code depends on my Groovy code, not the other way around. However, Kotlin compiles my code first instead of Groovy, and, as a result, I get errors like Unresolved reference: SiteRepository

Any suggestions how I can fix this, by either changing the build sequence, or Kotlin depending explicitly on Groovy, or any other suggestion?

like image 864
Erik Pragt Avatar asked Mar 25 '16 05:03

Erik Pragt


People also ask

How do I convert Groovy to kts?

Because you can combine Groovy and KTS build files in a project, a simple way to start converting your project to KTS is to select a simple build file, like settings. gradle , rename it to settings. gradle. kts , and convert its contents to KTS.

What is the difference between Groovy and Kotlin?

Google announced Kotlin as the official language for android development, whereas Groovy can be used for scripting purposes. In Kotlin, a class can be marked as a data class, which provides standard functions and utility functions. Groovy 1.8 provided few new transformations like @ToString & @EqualsAndHashCode.

How do I enable Kotlin DSL?

To activate the Kotlin DSL, simply use the . gradle. kts extension for your build scripts in place of . gradle .


1 Answers

It can be done like so:

After 4.10

Kotlin First:

//compileKotlin.dependsOn = compileKotlin.taskDependencies.values - 'compileJava' compileGroovy.dependsOn compileKotlin compileGroovy.classpath += files(compileKotlin.destinationDir) classes.dependsOn compileGroovy 

Before 4.10

Groovy First:

compileGroovy.dependsOn = compileGroovy.taskDependencies.values - 'compileJava' compileKotlin.dependsOn compileGroovy compileKotlin.classpath += files(compileGroovy.destinationDir) classes.dependsOn compileKotlin 

or Kotlin First:

compileKotlin.dependsOn = compileKotlin.taskDependencies.values - 'compileJava' compileGroovy.dependsOn compileKotlin compileGroovy.classpath += files(compileKotlin.destinationDir) classes.dependsOn compileGroovy 

To be clear, you get to choose whether your Kotlin code depends on Groovy or Groovy on Kotlin, but you don't get to have it both ways.

like image 197
Jonathan Schneider Avatar answered Sep 21 '22 19:09

Jonathan Schneider