Skip to content

Commit

Permalink
feat(kotlin): pin kotlin-compiler-embeddable dependency in support …
Browse files Browse the repository at this point in the history
…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 <artyom.shendrik@gmail.com>
  • Loading branch information
amal committed Nov 25, 2024
1 parent 8f0174f commit bb704a1
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions fluxo-kmp-conf/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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] == '.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
1 change: 1 addition & 0 deletions self/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit bb704a1

Please sign in to comment.