Skip to content

Report an actionable error on Kotlin compiler plugin version mismatch - #8554

Open
timtebeek wants to merge 5 commits into
mainfrom
tim/kotlin-plugin-version-mismatch-error
Open

Report an actionable error on Kotlin compiler plugin version mismatch#8554
timtebeek wants to merge 5 commits into
mainfrom
tim/kotlin-plugin-version-mismatch-error

Conversation

@timtebeek

@timtebeek timtebeek commented Aug 19, 2026

Copy link
Copy Markdown
Member

When a consumer puts rewrite-kotlin on their kotlinCompilerPluginClasspath but their kotlin("jvm") version differs from the one rewrite-kotlin was built against, registering the FIR/IR extensions dies with a raw ClassCastException that Gradle surfaces only as "Internal compiler error. See log for more details" — symmetrically, for both older and newer consumer compilers.

Registration is now wrapped so LinkageError (including AbstractMethodError) and ClassCastException are reported through the message collector as a compiler error naming the compiler actually running the build, the Kotlin version rewrite-kotlin was built against, and the kotlin("jvm") alignment to make. Since KotlinCompilerVersion always reports the running compiler, the build emits kotlinVersion into META-INF/rewrite-kotlin-compiler.version for the plugin to read at runtime.

  • Tests cover the reported message for each failure type, the no-message-collector fallback, and an end-to-end compilation asserting the error fails the build instead of crashing the compiler. The build-script change is appended at the end of the file to avoid conflicting with migrate to Kotlin 2.4.10 #8542.

When a consumer puts rewrite-kotlin on their kotlinCompilerPluginClasspath
with a kotlin("jvm") version other than the one rewrite-kotlin was built
against, registering the FIR/IR extensions dies with a raw ClassCastException
that Gradle surfaces only as "Internal compiler error. See log for more
details".

Wrap registration so LinkageError and ClassCastException are reported through
the message collector as a compiler error naming the running compiler, the
Kotlin version rewrite-kotlin was built against, and the kotlin("jvm")
alignment to make. KotlinCompilerVersion always reports the running compiler,
so the build emits kotlinVersion into META-INF/rewrite-kotlin-compiler.version
for the plugin to read at runtime.

Fixes #8270
Degrade gracefully when the built-against version resource is absent rather
than telling the consumer to align with "unknown", and treat a discarding
MessageCollector.NONE like a missing collector so the error can never be
swallowed into a silently unregistered plugin.

Reuse RecipePluginCompileFixture for the end-to-end compilation test instead
of hand-rolling a second KotlinCompilation setup.
@timtebeek timtebeek added kotlin enhancement New feature or request labels Aug 19, 2026
Nothing already in the jar records the Kotlin version rewrite-kotlin was
compiled against: MANIFEST.MF and its rewrite-kotlin.properties mirror describe
the module, META-INF/compiler.version belongs to the running compiler, and the
@metadata stamp only carries the coarse ABI metadata version.

Emit the value as a generated internal const instead of a resource. It is
inlined into bytecode, so it resolves identically from a jar, from classes
dirs, and in tests, which removes the missing-resource fallback entirely.
Reporting runs through the same compiler API surface whose version skew is
being diagnosed, so wrap the collector lookup and report; on LinkageError,
fall through to throwing the actionable message with the original cause rather
than replacing it with the reporting failure.

Also correct the fixture ClassCastException to the cast direction observed
running against kotlin-compiler-embeddable 2.4.10.
@timtebeek
timtebeek marked this pull request as ready for review August 19, 2026 22:20
@timtebeek timtebeek moved this from In Progress to Ready to Review in OpenRewrite Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request kotlin

Projects

Status: Ready to Review

Development

Successfully merging this pull request may close these issues.

1 participant