Skip to content

Commit

Permalink
Temporary fix: Override Kotlin version in the plugin module
Browse files Browse the repository at this point in the history
Fixes issue #236.
Eventually, the plugin should use the version of Kotlin embedded into Gradle.
  • Loading branch information
qurbonzoda authored and woainikk committed Sep 4, 2024
1 parent 724d654 commit 91b1ead
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
30 changes: 25 additions & 5 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapperKt
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask

buildscript {
Expand All @@ -15,10 +16,16 @@ buildscript {

dependencies {
classpath(libs.kotlinx.teamInfraGradlePlugin)
// Note: unlike the root project, don't override KGP version in this project.
// Gradle plugins should only use the embedded-kotlin version.
// kotlinx-benchmark uses an external KGP the moment... but that should be fixed
// https://github.com/Kotlin/kotlinx-benchmark/issues/244

String kotlinVersion = providers.gradleProperty("kotlin_version").orNull
if (kotlinVersion != null && !kotlinVersion.isBlank()) {
// In addition to overriding the Kotlin version in the Version Catalog,
// also enforce the KGP version using a dependency constraint.
// Constraints are stricter than Version Catalog.
constraints {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
}
}
}
}

Expand All @@ -43,7 +50,20 @@ infra {
}
}

logger.info("Using Kotlin ${libs.versions.kotlin.get()} for project ${project.name}")
String currentKgpVersion = KotlinPluginWrapperKt.getKotlinPluginVersion(project)
logger.info("Using Kotlin Gradle Plugin ${currentKgpVersion} for project ${project.name}")

String kotlinVersionOverride = providers.gradleProperty("kotlin_version").getOrNull()

if (kotlinVersionOverride != null) {
String versionCatalogKotlinVersion = libs.versions.kotlin.get()
if (kotlinVersionOverride != versionCatalogKotlinVersion) {
throw new IllegalStateException("Kotlin version in Version Catalog was not overridden. Expected:$kotlinVersionOverride, actual:$versionCatalogKotlinVersion.")
}
if (kotlinVersionOverride != currentKgpVersion) {
throw new IllegalStateException("Kotlin Gradle Plugin version was not overridden. Expected:$kotlinVersionOverride, actual:$currentKgpVersion.")
}
}

repositories {
mavenCentral()
Expand Down
8 changes: 8 additions & 0 deletions plugin/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))

String kotlinVersion = providers.gradleProperty("kotlin_version").orNull
if (kotlinVersion != null && !kotlinVersion.isBlank()) {
// Override the default Kotlin version.
// The only intended use-case is for testing dev Kotlin builds using kotlinx-benchmark.
// The Kotlin version should not be overridden during regular development.
version("kotlin", kotlinVersion)
}
}
}
}
Expand Down

0 comments on commit 91b1ead

Please sign in to comment.