Issue
Using a very recent version of gradle (8.5) I want to compile Groovy code before Kotlin code. This will enable me to gradually migrate the entire project from Groovy to Kotlin using a top-down approach. (i.e., migrate one controller to Kotlin while the underlying dependencies remain in Groovy).
The Kotlin gradle plugin seems to update the task requirements, forcing the Kotlin compilation to happen first.
- Kotlin plugin wants to happen after the
compileJava
- Groovy plugin wants to perform
compileJava
first Thus, I can't do a compileGroovy without it triggering a compileKotlin which prevents my goal from above.
TaskTree ouptut:
:compileGroovy
\--- :compileJava
\--- :compileKotlin
\--- :checkKotlinGradlePluginConfigurationErrors
plugins used in build.gradle
:
plugins {
id 'groovy'
id 'application'
id 'org.jetbrains.kotlin.jvm' version '2.0.0-Beta2'
id "com.dorongold.task-tree" version "2.1.1"
id 'idea'
}
Steps to reproduce:
- place a Groovy class file in
src/main/groovy
(i.e., Author) - place a Kotlin class file in
src/main/kotlin
that depends on that Groovy class. (i.e., Book)
Additional research notes:
- The solution provided for an earlier Gradle version is no longer working: Gradle 6+ : compile groovy before kotlin (there is an error message about 'classpath' as unknown property for compileKotlin)
- Here is another one that does not work: Compile Groovy and Kotlin?
- And yet another approach that no longer works: Gradle Kotlin Dsl Build for a Kotlin Gradle Plugin, which depends on a Groovy Class in the same Project
Solution
The base idea of the documentation at https://docs.gradle.org/current/userguide/building_java_projects.html#sub:compile_deps_jvm_lang and thus the solution in Gradle 6+ : compile groovy before kotlin you posted stays the same.
You remove the groovy => java
dependency and add a kotlin => groovy
dependency.
That the linked answer does not literally work has nothing to do with Gradle 6 vs. Gradle 8.
Your problem is Kotlin Gradle Plugin <1.8 vs. >=1.8 as in 1.8 the deprecated classpath
property was finally made an error and later removed, in favor of libraries
.
So here the version of the configuration that works with your version as Kotlin DSL snippet:
tasks.compileGroovy {
classpath = sourceSets.main.get().compileClasspath
}
tasks.compileKotlin {
libraries.from(sourceSets.main.get().groovy.classesDirectory)
}
Answered By - Vampire
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.