This is an automated email from the ASF dual-hosted git repository.

vladimirsitnikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit 3c38098347f5d69e452a0538e916a262e080e9c0
Author: Vladimir Sitnikov <[email protected]>
AuthorDate: Fri Nov 24 13:34:45 2023 +0300

    chore: use toolchains for kotlin-dsl for Gradle 9 compatibility
---
 build-logic-commons/gradle-plugin/build.gradle.kts | 25 +++++++---------------
 ...build-logic.kotlin-dsl-gradle-plugin.gradle.kts | 14 ++++++++----
 2 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/build-logic-commons/gradle-plugin/build.gradle.kts 
b/build-logic-commons/gradle-plugin/build.gradle.kts
index e0c21fbb0a..97cd2f00d9 100644
--- a/build-logic-commons/gradle-plugin/build.gradle.kts
+++ b/build-logic-commons/gradle-plugin/build.gradle.kts
@@ -16,8 +16,6 @@
  */
 
 import org.gradle.kotlin.dsl.support.expectedKotlinDslPluginsVersion
-import org.jetbrains.kotlin.gradle.dsl.JvmTarget
-import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
 
 plugins {
     `kotlin-dsl`
@@ -34,20 +32,13 @@ dependencies {
 }
 
 // We need to figure out a version that is supported by the current JVM, and 
by the Kotlin Gradle plugin
-val currentJava = JavaVersion.current()
-if (currentJava > JavaVersion.VERSION_1_8) {
-    // We want an LTS Java release for build script compilation
-    val latestSupportedLts = listOf("17", "11")
-        .intersect(JvmTarget.values().mapTo(mutableSetOf()) { it.target })
-        .first { JavaVersion.toVersion(it) <= currentJava }
-
-    tasks.withType<JavaCompile>().configureEach {
-        
options.release.set(JavaVersion.toVersion(latestSupportedLts).majorVersion.toInt())
-    }
-
-    tasks.withType<KotlinCompile>().configureEach {
-        kotlinOptions {
-            jvmTarget = latestSupportedLts
+// So we settle on 17 or 11 if the current JVM supports it
+listOf(17, 11)
+    .firstOrNull { JavaVersion.toVersion(it) <= JavaVersion.current() }
+    ?.let { buildScriptJvmTarget ->
+        java {
+            toolchain {
+                
languageVersion.set(JavaLanguageVersion.of(buildScriptJvmTarget))
+            }
         }
     }
-}
diff --git 
a/build-logic-commons/gradle-plugin/src/main/kotlin/build-logic.kotlin-dsl-gradle-plugin.gradle.kts
 
b/build-logic-commons/gradle-plugin/src/main/kotlin/build-logic.kotlin-dsl-gradle-plugin.gradle.kts
index 278d417402..f5e6975251 100644
--- 
a/build-logic-commons/gradle-plugin/src/main/kotlin/build-logic.kotlin-dsl-gradle-plugin.gradle.kts
+++ 
b/build-logic-commons/gradle-plugin/src/main/kotlin/build-logic.kotlin-dsl-gradle-plugin.gradle.kts
@@ -25,8 +25,14 @@ tasks.validatePlugins {
     enableStricterValidation.set(true)
 }
 
-java {
-    toolchain {
-        languageVersion.set(JavaLanguageVersion.of(17))
+// We need to figure out a version that is supported by the current JVM, and 
by the Kotlin Gradle plugin
+// So we settle on 17 or 11 if the current JVM supports it
+listOf(17, 11)
+    .firstOrNull { JavaVersion.toVersion(it) <= JavaVersion.current() }
+    ?.let { buildScriptJvmTarget ->
+        java {
+            toolchain {
+                
languageVersion.set(JavaLanguageVersion.of(buildScriptJvmTarget))
+            }
+        }
     }
-}

Reply via email to