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?
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.
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.
To activate the Kotlin DSL, simply use the . gradle. kts extension for your build scripts in place of . gradle .
It can be done like so:
Kotlin First:
//compileKotlin.dependsOn = compileKotlin.taskDependencies.values - 'compileJava' compileGroovy.dependsOn compileKotlin compileGroovy.classpath += files(compileKotlin.destinationDir) classes.dependsOn compileGroovy
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With