From cb5337a48f869ff3c44d6716e4ae942c3ba295b6 Mon Sep 17 00:00:00 2001 From: Art Shendrik Date: Mon, 25 Nov 2024 13:53:39 +0000 Subject: [PATCH] feat(kotlin): pin `kotlin-compiler-embeddable` dependency in support for Kotlin 2.1 - Add kotlin-compiler-embeddable dependency to build scripts - Introduce KOTLIN_2_1 version constant - Pin kotlin-compiler-embeddable to Kotlin plugin version >= 2.1.0 - Update libs.versions.toml with kotlin-compiler-embeddable details More details on the matter: https://kotlinlang.slack.com/archives/C0KLZSCHF/p1729256644747559?thread_ts=1729151089.194689&cid=C0KLZSCHF Signed-off-by: Art Shendrik --- CHANGELOG.md | 3 +++ fluxo-kmp-conf/build.gradle.kts | 1 + .../dependencies/compileClasspath.txt | 2 +- .../dependencies/runtimeClasspath.txt | 7 ++++--- .../conf/feat/DependencyPinningBundle.kt | 19 ++++++++++++++++++- .../impl/kotlin/SetupKotlinCompatibility.kt | 2 ++ gradle/libs.versions.toml | 5 +++++ self/build.gradle.kts | 1 + 8 files changed, 35 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 952d5e6d..bd993ddf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ ### Added - add JVM compatibility and Kotlin options flags to disable a corresponding autoconfiguration. +### Fixed +- pin `kotlin-compiler-embeddable` dependency in support for Kotlin 2.1 ([more details](https://kotlinlang.slack.com/archives/C0KLZSCHF/p1729256644747559?thread_ts=1729151089.194689&cid=C0KLZSCHF)) + ## [0.13.0] - 2024-11-18 diff --git a/fluxo-kmp-conf/build.gradle.kts b/fluxo-kmp-conf/build.gradle.kts index 2182bf49..545a4099 100644 --- a/fluxo-kmp-conf/build.gradle.kts +++ b/fluxo-kmp-conf/build.gradle.kts @@ -89,6 +89,7 @@ dependencies { // Detekt ReportMergeTask is used internally implementation(libs.plugin.detekt) implementation(libs.detekt.core) + implementation(libs.kotlin.compiler.embeddable) // ASM for bytecode verification. implementation(libs.asm) diff --git a/fluxo-kmp-conf/dependencies/compileClasspath.txt b/fluxo-kmp-conf/dependencies/compileClasspath.txt index e870c199..7117ebf7 100644 --- a/fluxo-kmp-conf/dependencies/compileClasspath.txt +++ b/fluxo-kmp-conf/dependencies/compileClasspath.txt @@ -73,7 +73,7 @@ org.jetbrains.intellij.platform:intellij-platform-gradle-plugin:2.1.0 org.jetbrains.kotlin.plugin.compose:org.jetbrains.kotlin.plugin.compose.gradle.plugin:2.0.21 org.jetbrains.kotlin.plugin.sam.with.receiver:org.jetbrains.kotlin.plugin.sam.with.receiver.gradle.plugin:2.0.21 org.jetbrains.kotlin:compose-compiler-gradle-plugin:2.0.21 -org.jetbrains.kotlin:kotlin-compiler-embeddable:2.0.10 +org.jetbrains.kotlin:kotlin-compiler-embeddable:2.0.21 org.jetbrains.kotlin:kotlin-gradle-plugin-annotations:2.0.21 org.jetbrains.kotlin:kotlin-gradle-plugin-api:2.0.21 org.jetbrains.kotlin:kotlin-gradle-plugin-model:2.0.21 diff --git a/fluxo-kmp-conf/dependencies/runtimeClasspath.txt b/fluxo-kmp-conf/dependencies/runtimeClasspath.txt index c5f2ad04..bfe1d632 100644 --- a/fluxo-kmp-conf/dependencies/runtimeClasspath.txt +++ b/fluxo-kmp-conf/dependencies/runtimeClasspath.txt @@ -42,10 +42,11 @@ org.checkerframework:checker-qual:3.21.2 org.eclipse.jgit:org.eclipse.jgit:6.7.0.202309050840-r org.eclipse.platform:org.eclipse.osgi:3.18.300 org.jetbrains.intellij.deps:trove4j:1.0.20200330 -org.jetbrains.kotlin:kotlin-compiler-embeddable:2.0.10 -org.jetbrains.kotlin:kotlin-daemon-embeddable:2.0.10 +org.jetbrains.kotlin:kotlin-compiler-embeddable:2.0.21 +org.jetbrains.kotlin:kotlin-daemon-embeddable:2.0.21 org.jetbrains.kotlin:kotlin-reflect:2.0.10 -org.jetbrains.kotlin:kotlin-script-runtime:2.0.10 +org.jetbrains.kotlin:kotlin-script-runtime:2.0.21 +org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4 org.jetbrains.kotlinx:kotlinx-html-jvm:0.8.1 org.jetbrains.kotlinx:kotlinx-serialization-core-jvm:1.4.1 org.jetbrains.kotlinx:kotlinx-serialization-core:1.4.1 diff --git a/fluxo-kmp-conf/src/main/kotlin/fluxo/conf/feat/DependencyPinningBundle.kt b/fluxo-kmp-conf/src/main/kotlin/fluxo/conf/feat/DependencyPinningBundle.kt index aedc8d0e..789d92c4 100644 --- a/fluxo-kmp-conf/src/main/kotlin/fluxo/conf/feat/DependencyPinningBundle.kt +++ b/fluxo-kmp-conf/src/main/kotlin/fluxo/conf/feat/DependencyPinningBundle.kt @@ -2,6 +2,8 @@ package fluxo.conf.feat import fluxo.conf.FluxoKmpConfContext import fluxo.conf.data.VersionCatalogConstants.VC_PINNED_BUNDLE_ALIAS +import fluxo.conf.impl.kotlin.KOTLIN_2_1 +import fluxo.conf.impl.kotlin.KOTLIN_PLUGIN_VERSION_RAW import fluxo.conf.impl.logDependency import fluxo.log.d import fluxo.log.l @@ -21,6 +23,21 @@ internal fun FluxoKmpConfContext.prepareDependencyPinningBundle() { val p = rootProject val pinnedDeps: PinnedDeps = HashMap() + + if (kotlinPluginVersion >= KOTLIN_2_1) { + // KGP doesn't depend on the `kotlin-compiler-embeddable` dependency + // starting from Kotlin 2.1.0 + // Other plugins can bring incompatible versions of the compiler. + // https://kotlinlang.slack.com/archives/C0KLZSCHF/p1729256644747559?thread_ts=1729151089.194689&cid=C0KLZSCHF + val version = runCatching { KOTLIN_PLUGIN_VERSION_RAW }.getOrNull() + ?: kotlinPluginVersion.toString() + val compilerEmbeddable = object : ModuleIdentifier { + override fun getGroup() = "org.jetbrains.kotlin" + override fun getName() = "kotlin-compiler-embeddable" + } + pinnedDeps[compilerEmbeddable] = Pair(version, "Pinned to Kotlin plugin version") + } + val bundleAliases = libs.bundleAliases if (bundleAliases.isNotEmpty()) { for (alias in bundleAliases) { @@ -73,7 +90,7 @@ private fun FluxoKmpConfContext.collectPinnedDependencies( logger: Logger, pinnedDeps: PinnedDeps, ) { - // Filter "pinned and "pinned.*" bundles + // Filter "pinned" and "pinned.*" bundles alias.startsWith(ALIAS, ignoreCase = true) && alias.run { val l = length l == ALIAS.length || l > ALIAS.length && this[ALIAS.length] == '.' diff --git a/fluxo-kmp-conf/src/main/kotlin/fluxo/conf/impl/kotlin/SetupKotlinCompatibility.kt b/fluxo-kmp-conf/src/main/kotlin/fluxo/conf/impl/kotlin/SetupKotlinCompatibility.kt index f5039cb9..6d097068 100644 --- a/fluxo-kmp-conf/src/main/kotlin/fluxo/conf/impl/kotlin/SetupKotlinCompatibility.kt +++ b/fluxo-kmp-conf/src/main/kotlin/fluxo/conf/impl/kotlin/SetupKotlinCompatibility.kt @@ -81,6 +81,8 @@ internal val KOTLIN_2_0 = KotlinVersion(2, 0, 0) internal val KOTLIN_2_0_20 = KotlinVersion(2, 0, 20) +internal val KOTLIN_2_1 = KotlinVersion(2, 1, 0) + @Volatile internal var KOTLIN_PLUGIN_VERSION: KotlinVersion = KotlinVersion.CURRENT diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 734368e7..0ae6132e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -253,6 +253,11 @@ asm = { module = "org.ow2.asm:asm", version.ref = "asm" } # https://github.com/tschuchortdev/kotlin-compile-testing/releases. kotlin-compile-testing = { module = "dev.zacsweers.kctfork:core", version = "0.6.0" } +# Starting from Kotlin 2.1.0, KGP doesn't depend on the `kotlin-compiler-embeddable` dependency. +# Other plugins can bring incompatible versions of the compiler. +# https://kotlinlang.slack.com/archives/C0KLZSCHF/p1729256644747559?thread_ts=1729151089.194689&cid=C0KLZSCHF +kotlin-compiler-embeddable = { module = "org.jetbrains.kotlin:kotlin-compiler-embeddable", version.ref = "kotlin" } + # Annotations for JVM-based languages # https://mvnrepository.com/artifact/org.jetbrains/annotations # https://repo1.maven.org/maven2/org/jetbrains/annotations/ diff --git a/self/build.gradle.kts b/self/build.gradle.kts index ab0ed3ef..6dd58eb4 100644 --- a/self/build.gradle.kts +++ b/self/build.gradle.kts @@ -57,6 +57,7 @@ dependencies { // Detekt ReportMergeTask is used internally implementation(libs.plugin.detekt) implementation(libs.detekt.core) + implementation(libs.kotlin.compiler.embeddable) // ASM for bytecode verification. implementation(libs.asm)