Skip to content

Commit 84d7d0f

Browse files
ALikhachevqurbonzoda
authored andcommitted
Use fixated Kotlin compiler for compiling the Gradle plugin.
Relates to KT-60521
1 parent cadd5a4 commit 84d7d0f

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ logger.info("Using Kotlin Gradle Plugin $currentKgpVersion")
8080
val kotlinVersionOverride = providers.gradleProperty("kotlin_version").getOrNull()
8181

8282
if (kotlinVersionOverride != null) {
83-
val versionCatalogKotlinVersion = libs.versions.kotlin.get()
83+
val versionCatalogKotlinVersion = libs.versions.kotlin.asProvider().get()
8484
if (kotlinVersionOverride != versionCatalogKotlinVersion) {
8585
throw IllegalStateException("Kotlin version in Version Catalog was not overridden. Expected:$kotlinVersionOverride, actual:$versionCatalogKotlinVersion.")
8686
}

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# Note: Kotlin version can be overridden by passing `-Pkotlin_version=<version>`
44
kotlin = "2.0.20"
5+
kotlin-for-gradle-plugin = "2.0.20" # Kotlin 2.1 removes support for the used language version / api version: KT-60521
56
kotlinx-binaryCompatibilityValidator = "0.16.2"
67
kotlinx-teamInfra = "0.4.0-dev-81"
78
squareup-kotlinpoet = "1.3.0"

integration/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ tasks.test {
2424
systemProperty("plugin_repo_url", plugin.projectDir.resolve("build/maven").absoluteFile.invariantSeparatorsPath)
2525
systemProperty("runtime_repo_url", rootProject.buildDir.resolve("maven").absoluteFile.invariantSeparatorsPath)
2626
systemProperty("kotlin_repo_url", rootProject.properties["kotlin_repo_url"])
27-
systemProperty("kotlin_version", libs.versions.kotlin.get())
27+
systemProperty("kotlin_version", libs.versions.kotlin.asProvider().get())
2828
systemProperty("minSupportedGradleVersion", libs.versions.minSupportedGradle.get())
2929
systemProperty("minSupportedKotlinVersion", libs.versions.minSupportedKotlin.get())
3030
}

plugin/build.gradle.kts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
22
import kotlinx.team.infra.InfraExtension
3+
import org.jetbrains.kotlin.buildtools.api.ExperimentalBuildToolsApi
4+
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
35

46
buildscript {
57
repositories {
@@ -41,7 +43,7 @@ extensions.configure<InfraExtension> {
4143
}
4244
}
4345

44-
logger.info("Using Kotlin ${libs.versions.kotlin.get()} for project ${project.name}")
46+
logger.info("Using Kotlin ${libs.versions.kotlin.asProvider().get()} for project ${project.name}")
4547

4648
repositories {
4749
mavenCentral()
@@ -83,14 +85,26 @@ sourceSets {
8385
}
8486
}
8587

88+
kotlin {
89+
@OptIn(ExperimentalBuildToolsApi::class, ExperimentalKotlinGradlePluginApi::class)
90+
compilerVersion = libs.versions.kotlin.`for`.gradle.plugin.get()
91+
}
92+
8693
tasks.compileKotlin {
8794
compilerOptions {
8895
optIn.addAll(
8996
"kotlinx.benchmark.gradle.internal.KotlinxBenchmarkPluginInternalApi",
9097
"kotlin.RequiresOptIn",
9198
)
92-
@Suppress("DEPRECATION")
93-
apiVersion = KotlinVersion.KOTLIN_1_4 // the version of Kotlin embedded in Gradle
99+
/**
100+
* Those versions are configured according to https://docs.gradle.org/current/userguide/compatibility.html
101+
* and the Kotlin compiler compatibility policy stating that Kotlin 1.4 is compatible with 1.5 binaries
102+
*/
103+
@Suppress("DEPRECATION", "DEPRECATION_ERROR")
104+
run {
105+
languageVersion = KotlinVersion.KOTLIN_1_5
106+
apiVersion = KotlinVersion.KOTLIN_1_4
107+
}
94108
}
95109
}
96110

@@ -126,7 +140,7 @@ val generatePluginConstants by tasks.registering {
126140
val minSupportedKotlinVersion = libs.versions.minSupportedKotlin
127141
inputs.property("minSupportedKotlinVersion", minSupportedKotlinVersion)
128142

129-
val kotlinCompilerVersion = libs.versions.kotlin
143+
val kotlinCompilerVersion = libs.versions.kotlin.asProvider()
130144
inputs.property("kotlinCompilerVersion", kotlinCompilerVersion)
131145

132146
doLast {

plugin/gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ group=org.jetbrains.kotlinx
22
version=0.5.0-SNAPSHOT
33

44
kotlin.code.style=official
5+
6+
# to use fixated compiler for compiling Gradle plugin
7+
kotlin.compiler.runViaBuildToolsApi=true

0 commit comments

Comments
 (0)