Add Kotlin 2.0+ support for Gradle and IR compiler plugin (#435) - #487
Add Kotlin 2.0+ support for Gradle and IR compiler plugin (#435)#487kareemessam09 wants to merge 3 commits into
Conversation
Migrate kermit-ir-plugin to Kotlin 2.0+ CompilerPluginRegistrar with supportsK2 enabled. - Replace ComponentRegistrar with CompilerPluginRegistrar - Register IR extension via ExtensionStorage and use ClassId and org.jetbrains.kotlin.ir.util.isSubtypeOfClass - Drop obsolete kermit-ir-plugin-native module (unneeded in Kotlin 2.0+) - Remove getPluginArtifactForNative from KermitGradlePlugin - Replace kapt and auto-service with direct META-INF/services declarations - Modernize test suite with kctfork and add runtime execution verification test - Add KermitGradlePluginTest unit tests and ensure ktlint passes
|
Thanks for the contribution. I'll try to take some time to review it this week. Added Copilot for an initial round |
There was a problem hiding this comment.
🟡 Changes recommended
Kotlin 2.0 compatibility is unverified, and a supported non-embeddable Native configuration no longer receives the compiler plugin.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Restores Kermit’s Gradle and IR compiler plugins for modern Kotlin/K2 toolchains.
Changes:
- Migrates compiler registration and IR APIs to K2-compatible interfaces.
- Removes the legacy Native-specific plugin artifact.
- Restores publishing and expands compiler/plugin tests.
File summaries
| File | Description |
|---|---|
settings.gradle.kts |
Re-enables plugin modules. |
plugin/kermit-ir-plugin/src/test/kotlin/co/touchlab/kermit/irplugin/KermitStripperIrPluginTest.kt |
Restores compiler and runtime tests. |
plugin/kermit-ir-plugin/src/test/kotlin/co/touchlab/kermit/irplugin/Helper.kt |
Updates the test logger fixture. |
plugin/kermit-ir-plugin/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar |
Registers the compiler registrar. |
plugin/kermit-ir-plugin/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor |
Registers option processing. |
plugin/kermit-ir-plugin/src/main/kotlin/co/touchlab/kermit/irplugin/KermitIrGenerationExtension.kt |
Simplifies IR transformation setup. |
plugin/kermit-ir-plugin/src/main/kotlin/co/touchlab/kermit/irplugin/KermitCompilerPluginRegistrar.kt |
Migrates registration to K2 APIs. |
plugin/kermit-ir-plugin/src/main/kotlin/co/touchlab/kermit/irplugin/KermitCommandLineProcessor.kt |
Updates compiler API opt-in. |
plugin/kermit-ir-plugin/src/main/kotlin/co/touchlab/kermit/irplugin/KermitChiselTransformer.kt |
Modernizes IR lookup and transformation. |
plugin/kermit-ir-plugin/build.gradle.kts |
Updates testing and publishing. |
plugin/kermit-ir-plugin-native/gradle.properties |
Removes Native artifact metadata. |
plugin/kermit-ir-plugin-native/build.gradle.kts |
Removes the legacy Native module. |
plugin/kermit-ir-plugin-native/.gitignore |
Removes obsolete module configuration. |
plugin/kermit-gradle-plugin/src/test/kotlin/co/touchlab/kermit/gradle/KermitGradlePluginTest.kt |
Adds Gradle plugin unit tests. |
plugin/kermit-gradle-plugin/src/main/kotlin/co/touchlab/kermit/gradle/StripSeverity.kt |
Applies formatting updates. |
plugin/kermit-gradle-plugin/src/main/kotlin/co/touchlab/kermit/gradle/KermitGradlePlugin.kt |
Uses the unified compiler artifact. |
plugin/kermit-gradle-plugin/build.gradle.kts |
Adds tests and publishing configuration. |
gradle/libs.versions.toml |
Adds compiler-testing and publishing aliases. |
build.gradle.kts |
Enables publishing and API exclusions. |
Review details
- Files reviewed: 18/19 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| override fun applyToCompilation( | ||
| kotlinCompilation: KotlinCompilation<*> | ||
| ): Provider<List<SubpluginOption>> { | ||
| override fun applyToCompilation(kotlinCompilation: KotlinCompilation<*>): Provider<List<SubpluginOption>> { |
| testImplementation(kotlin("test-junit")) | ||
| testImplementation("org.jetbrains.kotlin:kotlin-compiler-embeddable") | ||
| testImplementation("com.github.tschuchortdev:kotlin-compile-testing:1.4.8") | ||
| testImplementation("dev.zacsweers.kctfork:core:0.12.1") |
There was a problem hiding this comment.
Can you please use the item from the version catalog?
|
Hi @faogustavo, thanks for taking a look! Looking forward to your review whenever you have time this week. In the meantime, I looked into the points raised by Copilot's automated review:
|
faogustavo
left a comment
There was a problem hiding this comment.
Can you also update any of the samples to include an example of plugin usage?
| @OptIn(ExperimentalCompilerApi::class) | ||
| fun compile(sourceFiles: List<SourceFile>, stripBelow: String = "None"): JvmCompilationResult = KotlinCompilation().apply { | ||
| sources = sourceFiles | ||
| compilerPluginRegistrars = listOf(KermitCompilerPluginRegistrar(stripBelow)) | ||
| inheritClassPath = true | ||
| }.compile() |
There was a problem hiding this comment.
The tests seem to only run a JVM compilation. Is there a way to also test a kotlin native compilation?
| testImplementation(kotlin("test-junit")) | ||
| testImplementation("org.jetbrains.kotlin:kotlin-compiler-embeddable") | ||
| testImplementation("com.github.tschuchortdev:kotlin-compile-testing:1.4.8") | ||
| testImplementation("dev.zacsweers.kctfork:core:0.12.1") |
There was a problem hiding this comment.
Can you please use the item from the version catalog?
… for dependencies
|
Hi @faogustavo, thanks for the review! I've addressed the feedback in the last commit:
|
Fixes #435
Context: #424 (comment) (cc @samhill303)
Summary
Restores and modernizes the Kermit Gradle plugin and IR compiler plugin for Kotlin 2.0+ (K2) support. In Kermit 1.x, the plugin was used to strip log statements at compile-time, but was disabled during the 2.0 migration due to Kotlin compiler internal changes.
Implementation notes
CompilerPluginRegistrarMigration: Replaced deprecatedComponentRegistrarwithCompilerPluginRegistrarwithsupportsK2 = trueandpluginId. Extensions are now registered viaExtensionStorage.referenceClass(FqName)toClassId, and migratedisSubtypeOfClasstoorg.jetbrains.kotlin.ir.util.isSubtypeOfClass. Added@OptIn(UnsafeDuringIrConstructionAPI::class, DeprecatedForRemovalCompilerApi::class)to handle IR receiver inspection safely.kermit-ir-plugin-nativemodule and removedgetPluginArtifactForNative()fromKermitGradlePlugin, as Kotlin 2.0+ unifies native IR compiler plugins via standard JVM jar artifacts.kaptandauto-servicewith directMETA-INF/servicesdescriptor files forCompilerPluginRegistrarandCommandLineProcessor.dev.zacsweers.kctfork:core:0.12.1(aligned with the project's Kotlin 2.3 toolchain). Un-ignored and updated all compiler tests, including an active runtime execution test that verifies stripped log lambdas produce zero invocations/side-effects.kermit,kermit-core,kermit-test, samples) are completely untouched.Testing
Commands run locally:
./gradlew :kermit-ir-plugin:test(5/5 tests passed, including runtime bytecode execution test)./gradlew :kermit-gradle-plugin:test(3/3 unit tests passed)./gradlew :kermit:jvmTest :kermit-core:jvmTest(existing modules pass with zero regressions)./gradlew :kermit-ir-plugin:ktlintCheck :kermit-gradle-plugin:ktlintCheck(0 lint violations)Platforms verified
linux_x64), JVM targets, and Kotlin IR compiler plugin transformations.macos,ios,watchos,tvos) were not built locally due to running on a Linux host without Apple SDKs.User-facing impact
Users on Kotlin 2.0+ can once again apply
id("co.touchlab.kermit")in Gradle and configurekermit { stripBelow = StripSeverity.<Level> }to strip log statements at compile time.Documentation
(Note: Happy to add a documentation page restoring the "Kermit Chisel" guide in
website/docs/if requested).