Hi everyone! I'm working on adding <OpenRewrite> s...
# gradle
t
Hi everyone! I'm working on adding OpenRewrite support for Kotlin 2.+. I am trying to build on top of the following PR. When trying to build the
rewrite-kotlin
module I get the following error:
Copy code
Caused by: java.lang.NoSuchMethodError: 'org.jetbrains.kotlin.buildtools.api.jvm.ClasspathEntrySnapshot org.jetbrains.kotlin.buildtools.api.CompilationService.calculateClasspathSnapshot(java.io.File, org.jetbrains.kotlin.buildtools.api.jvm.ClassSnapshotGranularity, boolean)'
along with the following warning:
Copy code
w: ⚠️ 'org.jetbrains.kotlin:kotlin-compiler-embeddable' Artifact Present in Build Classpath
The artifact `org.jetbrains.kotlin:kotlin-compiler-embeddable` is present in the build classpath along Kotlin Gradle plugin.
This may lead to unpredictable and inconsistent behavior.
I think it's important mentioning that I get when same error even when just trying to upgrade from Kotlin 1.9.25 to 2.2.0 in the main repo without the changes from the PR. From what I understand the cause of the error is a transitive dependency from the Kotlin Gradle plugin that introduces an older version on the build class path. So far I have tried to fix this by doing the following: 1. Exploring the config files for any hardcoded old Kotlin version, but nothing was found. 2. Commenting out the dependencies in the
build.gradle.kts
file of rewrite-kotlin
module
to prevent transitive leaks. Nothing changed. 3. Using the following command:
./gradlew :rewrite-kotlin:dependencies | grep -A 5 "kotlin-compiler-embeddable"
to check which version of
kotlin-compiler-embeddable
was Gradle resolving. The versions all appeared to match the set Kotlin language version. 4. Disabled classpath snapshots into
gradle.properties
by adding:
kotlin.incremental.useClasspathSnapshot=false
. Nothing changed. 5. Testing multiple Gradle/JDK combinations: Gradle versions between 8.14.3 & 9.0.0 with JDK 17, 21, 23, 24. Nothing changed. Does anyone have any pointers on what could be going wrong and how to fix it?
t
it looks like something forcing incosistent version of dependencies that KGP manages. Could you share a Gradle build scan?
m
Copy code
./gradlew :buildEnvironment

------------------------------------------------------------
Root project 'rewrite' - Eliminate tech-debt. Automatically.
------------------------------------------------------------

classpath
+--- org.openrewrite.build.root:org.openrewrite.build.root.gradle.plugin:latest.release -> 2.3.0
|    \--- org.openrewrite:rewrite-build-gradle-plugin:2.3.0
|         +--- org.openrewrite:rewrite-gradle:8.56.1
|         |    +--- org.openrewrite:rewrite-kotlin:8.56.1
|         |    |    +--- org.jetbrains:annotations:26.0.2 -> 13.0
|         |    |    +--- org.openrewrite:rewrite-java:8.56.1 (*)
|         |    |    +--- org.jetbrains.kotlin:kotlin-compiler-embeddable:1.9.25 -> 2.2.10
The rewrite-gradle-plugin pulls its own
kotlin-compiler-embeddable
, which might or might not be compatible with the one from KGP
👍 1
I'd recommend isolating the work of
rewrite-gradle-plugin
in isolated classloaders
t
@tapchicoma thank you! I tried to create a build scan, I am currently unable to, because I don't have a Develocity account. I will work on getting a build scan. @mbonnin thank you for the suggestion, I will try implementing it.
v
because I don't have a Develocity account
Isn't this about FOSS? Just create one on scans.gradle.org?
t
You're right, this is the build scan: https://scans.gradle.com/s/66fl7l6tzztd6
v
You apply the
org.openrewrite.build.root
plugin 2.3.0 which depends on
rewrite-kotlin
8.56.1 which depends on
kotlin-compiler-embeddable
1.9.25 I'd say and with that the newer KGP is not happy.
2
Regarding that warning about the embeddable compiler that is