Skip to content

Commit 2a5d322

Browse files
romtsnclaude
andcommitted
fix(ci): Dynamically set Kotlin language version based on compiler
Kotlin 2.3+ dropped support for language version 1.8. Use 2.0 when building with Kotlin 2.3+, otherwise keep 1.8. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 079ba77 commit 2a5d322

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

plugin-build/build.gradle.kts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import java.util.Properties
55
import org.gradle.api.tasks.testing.logging.TestLogEvent
66
import org.jetbrains.kotlin.config.KotlinCompilerVersion
77
import org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11
8-
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_8
8+
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
99
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
1010

1111
plugins {
@@ -91,8 +91,15 @@ tasks.withType<KotlinCompile>().configureEach {
9191

9292
compilerOptions {
9393
jvmTarget.set(JVM_11)
94-
languageVersion.set(KOTLIN_1_8)
95-
apiVersion.set(KOTLIN_1_8)
94+
// Kotlin supports current + 3 previous language versions.
95+
// We want 1.8, but if the compiler no longer supports it, use the oldest it does support.
96+
// e.g. Kotlin 2.1 oldest=1.8, Kotlin 2.3 oldest=2.0
97+
val compilerParts = KotlinCompilerVersion.VERSION.split(".")
98+
val compilerFlat = compilerParts[0].toInt() * 10 + compilerParts[1].toInt()
99+
val oldestFlat = maxOf(compilerFlat - 3, 18) // 18 = Kotlin 1.8
100+
val kotlinLangVersion = KotlinVersion.valueOf("KOTLIN_${oldestFlat / 10}_${oldestFlat % 10}")
101+
languageVersion.set(kotlinLangVersion)
102+
apiVersion.set(kotlinLangVersion)
96103
}
97104
}
98105

0 commit comments

Comments
 (0)