What version of OpenRewrite are you using?
Latest (rewrite-kotlin currently built against Kotlin 2.3.20).
How are you running OpenRewrite?
As a recipe-authoring consumer via the kotlin-recipe-starter, which puts rewrite-kotlin on kotlinCompilerPluginClasspath to use the Kotlin recipe DSL.
Problem
rewrite-kotlin is pinned to the Kotlin 2.3.x compiler, so consumers cannot move their own kotlin("jvm") Gradle plugin to Kotlin 2.4.x. When they do, compilation of their recipe module fails during :compileKotlin:
e: java.lang.ClassCastException:
org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrarAdapter$Companion
cannot be cast to org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
> Task :compileKotlin FAILED
> Internal compiler error. See log for more details
Root cause
The Kotlin recipe DSL is a K2 compiler plugin shipped inside rewrite-kotlin
(RecipeCompilerPluginRegistrar → FirExtensionRegistrarAdapter.registerExtension(...)), compiled against kotlin-compiler-embeddable:2.3.20 (rewrite-kotlin/build.gradle.kts, val kotlinVersion = "2.3.20"). The @ExperimentalCompilerApi FIR extension-registration internals are not binary-stable across Kotlin minor versions, so a plugin built for 2.3 cannot be loaded by the 2.4 compiler. This hard-couples a consumer's kotlin("jvm") version to the Kotlin version rewrite-kotlin was built against.
Requested change
Support Kotlin 2.4+ in rewrite-kotlin. Expected work:
- Bump
kotlinVersion (kotlin-compiler-embeddable/reflect/stdlib + kotlin-bom) in rewrite-kotlin/build.gradle.kts to 2.4.x.
- Bump the
kotlin("jvm") plugin used to build rewrite-kotlin itself.
- Update the lockstep
kotlin-bom pins in rewrite-gradle/build.gradle.kts and rewrite-maven/build.gradle.kts (both currently 2.3.20).
- Fix compile breaks from Kotlin
2.3 → 2.4 FIR/IR/compiler-plugin API changes in the parser (KotlinParser, ScriptCompilerPlugin) and the recipe DSL plugin (RecipeCompilerPluginRegistrar, RecipeFirExtensionRegistrar, RecipeIrGenerationExtension).
- Publish and align
rewrite-recipe-bom so consumers can move to Kotlin 2.4.x.
Are you interested in contributing a fix to OpenRewrite?
Possibly.
What version of OpenRewrite are you using?
Latest (
rewrite-kotlincurrently built against Kotlin2.3.20).How are you running OpenRewrite?
As a recipe-authoring consumer via the kotlin-recipe-starter, which puts
rewrite-kotlinonkotlinCompilerPluginClasspathto use the Kotlin recipe DSL.Problem
rewrite-kotlinis pinned to the Kotlin2.3.xcompiler, so consumers cannot move their ownkotlin("jvm")Gradle plugin to Kotlin2.4.x. When they do, compilation of their recipe module fails during:compileKotlin:2.3.20→2.4.10); CI: https://github.com/moderneinc/kotlin-recipe-starter/actions/runs/29453236383/job/87480488714Root cause
The Kotlin recipe DSL is a K2 compiler plugin shipped inside
rewrite-kotlin(
RecipeCompilerPluginRegistrar→FirExtensionRegistrarAdapter.registerExtension(...)), compiled againstkotlin-compiler-embeddable:2.3.20(rewrite-kotlin/build.gradle.kts,val kotlinVersion = "2.3.20"). The@ExperimentalCompilerApiFIR extension-registration internals are not binary-stable across Kotlin minor versions, so a plugin built for 2.3 cannot be loaded by the 2.4 compiler. This hard-couples a consumer'skotlin("jvm")version to the Kotlin versionrewrite-kotlinwas built against.Requested change
Support Kotlin
2.4+inrewrite-kotlin. Expected work:kotlinVersion(kotlin-compiler-embeddable/reflect/stdlib+kotlin-bom) inrewrite-kotlin/build.gradle.ktsto2.4.x.kotlin("jvm")plugin used to buildrewrite-kotlinitself.kotlin-bompins inrewrite-gradle/build.gradle.ktsandrewrite-maven/build.gradle.kts(both currently2.3.20).2.3 → 2.4FIR/IR/compiler-plugin API changes in the parser (KotlinParser,ScriptCompilerPlugin) and the recipe DSL plugin (RecipeCompilerPluginRegistrar,RecipeFirExtensionRegistrar,RecipeIrGenerationExtension).rewrite-recipe-bomso consumers can move to Kotlin2.4.x.Are you interested in contributing a fix to OpenRewrite?
Possibly.