Report an actionable error on Kotlin compiler plugin version mismatch - #8554
Open
timtebeek wants to merge 5 commits into
Open
Report an actionable error on Kotlin compiler plugin version mismatch#8554timtebeek wants to merge 5 commits into
timtebeek wants to merge 5 commits into
Conversation
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.
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
marked this pull request as ready for review
August 19, 2026 22:20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a consumer puts rewrite-kotlin on their
kotlinCompilerPluginClasspathbut theirkotlin("jvm")version differs from the one rewrite-kotlin was built against, registering the FIR/IR extensions dies with a rawClassCastExceptionthat 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(includingAbstractMethodError) andClassCastExceptionare 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 thekotlin("jvm")alignment to make. SinceKotlinCompilerVersionalways reports the running compiler, the build emitskotlinVersionintoMETA-INF/rewrite-kotlin-compiler.versionfor the plugin to read at runtime.