Skip to content

Commit 2d29655

Browse files
Run Gradle plugin compilation via fixated Kotlin compiler version (#472)
* Run Gradle plugin compilation via fixated Kotlin compiler version This also changes LV/AV of :atomicfu-transformer as it is as a runtime dependency of the plugin and contributes to compatibility with Gradle. In future, it's preferred to get rid of the dependency and use it through isolated classpath and Gradle Workers API. Relates to KT-60521 * Update :atomicfu-transformer apiDump --------- Co-authored-by: Maria Sokolova <[email protected]>
1 parent 5fc6179 commit 2d29655

File tree

9 files changed

+41
-10
lines changed

9 files changed

+41
-10
lines changed

atomicfu-gradle-plugin/build.gradle.kts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@ plugins {
66
alias(libs.plugins.gradle.pluginPublish)
77
id("kotlin-jvm-conventions")
88
id("java-gradle-plugin")
9-
}
10-
11-
// Gradle plugin must be compiled targeting the same Kotlin version as used by Gradle
12-
kotlin.sourceSets.configureEach {
13-
languageSettings {
14-
languageVersion = getOverridingKotlinLanguageVersion(project) ?: "1.4"
15-
apiVersion = getOverridingKotlinApiVersion(project) ?: "1.4"
16-
}
9+
id("gradle-compatibility")
1710
}
1811

1912
dependencies {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# to use fixated compiler for compiling Gradle plugin
2+
# configuration via project.extra is working since 2.1.0
3+
kotlin.compiler.runViaBuildToolsApi=true

atomicfu-transformer/api/atomicfu-transformer.api

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ public final class kotlinx/atomicfu/transformer/JvmVariant : java/lang/Enum {
190190
public static final field BOTH Lkotlinx/atomicfu/transformer/JvmVariant;
191191
public static final field FU Lkotlinx/atomicfu/transformer/JvmVariant;
192192
public static final field VH Lkotlinx/atomicfu/transformer/JvmVariant;
193-
public static fun getEntries ()Lkotlin/enums/EnumEntries;
194193
public static fun valueOf (Ljava/lang/String;)Lkotlinx/atomicfu/transformer/JvmVariant;
195194
public static fun values ()[Lkotlinx/atomicfu/transformer/JvmVariant;
196195
}

atomicfu-transformer/build.gradle.kts

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

55
plugins {
66
id("kotlin-jvm-publish-conventions")
7+
id("gradle-compatibility")
78
}
89

910
dependencies {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# to use fixated compiler for compiling Gradle plugin
2+
# configuration via project.extra is working since 2.1.0
3+
kotlin.compiler.runViaBuildToolsApi=true

atomicfu/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ kotlin {
3838
commonMain.dependencies {
3939
implementation("org.jetbrains.kotlin:kotlin-stdlib") {
4040
version {
41-
prefer(libs.versions.kotlin.get())
41+
prefer(libs.versions.kotlin.asProvider().get())
4242
}
4343
}
4444
}

buildSrc/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ plugins {
44

55
dependencies {
66
implementation(libs.kotlin.gradlePlugin)
7+
compileOnly(libs.kotlin.build.tools.api) // runtime dependency of KGP
78
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import org.jetbrains.kotlin.buildtools.api.ExperimentalBuildToolsApi
2+
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
3+
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
4+
5+
plugins {
6+
kotlin("jvm")
7+
}
8+
9+
project.extra["kotlin.compiler.runViaBuildToolsApi"] = "true"
10+
11+
kotlin {
12+
@OptIn(ExperimentalBuildToolsApi::class, ExperimentalKotlinGradlePluginApi::class)
13+
compilerVersion.set(
14+
versionCatalogs
15+
.named("libs")
16+
.findVersion("kotlin-for-gradle-plugin")
17+
.get()
18+
.requiredVersion
19+
)
20+
21+
// Gradle plugin must be compiled targeting the same Kotlin version as used by Gradle
22+
@Suppress("DEPRECATION", "DEPRECATION_ERROR")
23+
compilerOptions {
24+
languageVersion = getOverridingKotlinLanguageVersion(project)?.let { KotlinVersion.fromVersion(it) }
25+
?: KotlinVersion.KOTLIN_1_4
26+
apiVersion = getOverridingKotlinApiVersion(project)?.let { KotlinVersion.fromVersion(it) }
27+
?: KotlinVersion.KOTLIN_1_4
28+
}
29+
}

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[versions]
22
kotlin = "2.0.0"
3+
kotlin-for-gradle-plugin = "2.0.0" # Kotlin 2.1 removes support for the used language version / api version: KT-60521
34
kotlinx-binaryCompatibilityValidator = "0.16.0"
45
asm = "9.7"
56
slf4j = "1.8.0-alpha2"
@@ -15,6 +16,7 @@ gradle-develocity = "3.17.5"
1516

1617
# Kotlin dependencies
1718
kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
19+
kotlin-build-tools-api = { group = "org.jetbrains.kotlin", name = "kotlin-build-tools-api", version.ref = "kotlin" }
1820
kotlin-atomicfu = { group = "org.jetbrains.kotlin", name = "atomicfu", version.ref = "kotlin" }
1921
kotlin-stdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version.ref = "kotlin" }
2022
kotlin-stdlibJdk8 = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-jdk8", version.ref = "kotlin" }

0 commit comments

Comments
 (0)