Skip to content

Commit e9d9a20

Browse files
author
Abduqodiri Qurbonzoda
committed
Temporary fix: Override Kotlin version in the plugin module
Fixes issue #236. Eventually, the plugin should use the version of Kotlin embedded into Gradle.
1 parent 65af73f commit e9d9a20

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

plugin/build.gradle

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
2+
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapperKt
23
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
34

45
buildscript {
@@ -15,10 +16,16 @@ buildscript {
1516

1617
dependencies {
1718
classpath(libs.kotlinx.teamInfraGradlePlugin)
18-
// Note: unlike the root project, don't override KGP version in this project.
19-
// Gradle plugins should only use the embedded-kotlin version.
20-
// kotlinx-benchmark uses an external KGP the moment... but that should be fixed
21-
// https://github.com/Kotlin/kotlinx-benchmark/issues/244
19+
20+
String kotlinVersion = providers.gradleProperty("kotlin_version").orNull
21+
if (kotlinVersion != null && !kotlinVersion.isBlank()) {
22+
// In addition to overriding the Kotlin version in the Version Catalog,
23+
// also enforce the KGP version using a dependency constraint.
24+
// Constraints are stricter than Version Catalog.
25+
constraints {
26+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
27+
}
28+
}
2229
}
2330
}
2431

@@ -43,7 +50,20 @@ infra {
4350
}
4451
}
4552

46-
logger.info("Using Kotlin ${libs.versions.kotlin.get()} for project ${project.name}")
53+
String currentKgpVersion = KotlinPluginWrapperKt.getKotlinPluginVersion(project)
54+
logger.info("Using Kotlin Gradle Plugin ${currentKgpVersion} for project ${project.name}")
55+
56+
String kotlinVersionOverride = providers.gradleProperty("kotlin_version").getOrNull()
57+
58+
if (kotlinVersionOverride != null) {
59+
String versionCatalogKotlinVersion = libs.versions.kotlin.get()
60+
if (kotlinVersionOverride != versionCatalogKotlinVersion) {
61+
throw new IllegalStateException("Kotlin version in Version Catalog was not overridden. Expected:$kotlinVersionOverride, actual:$versionCatalogKotlinVersion.")
62+
}
63+
if (kotlinVersionOverride != currentKgpVersion) {
64+
throw new IllegalStateException("Kotlin Gradle Plugin version was not overridden. Expected:$kotlinVersionOverride, actual:$currentKgpVersion.")
65+
}
66+
}
4767

4868
repositories {
4969
mavenCentral()

plugin/settings.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ dependencyResolutionManagement {
1010
versionCatalogs {
1111
create("libs") {
1212
from(files("../gradle/libs.versions.toml"))
13+
14+
String kotlinVersion = providers.gradleProperty("kotlin_version").orNull
15+
if (kotlinVersion != null && !kotlinVersion.isBlank()) {
16+
// Override the default Kotlin version.
17+
// The only intended use-case is for testing dev Kotlin builds using kotlinx-benchmark.
18+
// The Kotlin version should not be overridden during regular development.
19+
version("kotlin", kotlinVersion)
20+
}
1321
}
1422
}
1523
}

0 commit comments

Comments
 (0)