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
The following commit(s) were added to refs/heads/master by this push:
new d077087997 chore: set Java LTS release for build script compilation
d077087997 is described below
commit d077087997dbf36c5f6a055a01286d173d4cb1b1
Author: Vladimir Sitnikov <[email protected]>
AuthorDate: Fri Nov 24 11:48:58 2023 +0300
chore: set Java LTS release for build script compilation
Previously the build failed if the default Java was newer than 20.
Now we explicitly specify jvmTarget for the build script compilation.
Note: it does not impact the target JVM for the resulting JMeter binaries.
---
build-logic-commons/gradle-plugin/build.gradle.kts | 23 ++++++++++++++++++++++
...build-logic.kotlin-dsl-gradle-plugin.gradle.kts | 21 ++++++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/build-logic-commons/gradle-plugin/build.gradle.kts
b/build-logic-commons/gradle-plugin/build.gradle.kts
index 59d18a29ea..90f37494f4 100644
--- a/build-logic-commons/gradle-plugin/build.gradle.kts
+++ b/build-logic-commons/gradle-plugin/build.gradle.kts
@@ -16,6 +16,8 @@
*/
import org.gradle.kotlin.dsl.support.expectedKotlinDslPluginsVersion
+import org.jetbrains.kotlin.gradle.dsl.JvmTarget
+import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
`kotlin-dsl`
@@ -29,4 +31,25 @@ dependencies {
// to make it work.
// See https://github.com/gradle/gradle/issues/17016 regarding
expectedKotlinDslPluginsVersion
implementation("org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:$expectedKotlinDslPluginsVersion")
+ // It seems to be the best way to make KotlinCompile available for use in
build-logic.kotlin-dsl-gradle-plugin.gradle.kts
+
implementation("org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:$embeddedKotlinVersion")
+}
+
+// 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("25", "21", "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
+ }
+ }
}
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 449e3c9b7c..ee27e739c3 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
@@ -15,6 +15,9 @@
* limitations under the License.
*/
+import org.jetbrains.kotlin.gradle.dsl.JvmTarget
+import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
+
plugins {
id("java-library")
id("org.gradle.kotlin.kotlin-dsl") // this is 'kotlin-dsl' without version
@@ -24,3 +27,21 @@ tasks.validatePlugins {
failOnWarning.set(true)
enableStricterValidation.set(true)
}
+
+val currentJava = JavaVersion.current()
+if (currentJava > JavaVersion.VERSION_1_8) {
+ // We want an LTS Java release for build script compilation
+ val latestSupportedLts = listOf("25", "21", "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
+ }
+ }
+}