From 4515c14ecd3c5bc290becea77942195445b08622 Mon Sep 17 00:00:00 2001 From: Martin Nonnenmacher Date: Tue, 12 Mar 2024 12:47:23 +0100 Subject: [PATCH] build: Set the target JVM to 11 Configure Gradle to build class files compatible with Java 11. This allows to use the published ORT artifacts also in Projects that use Java 11. Previously, Java 17 was required. The main use case for this is to be able to build the Analyzer Docker image for the ORT Server [1] with Java 11 which is required to analyze Gradle projects that are not compatible with newer Java versions. Relates to #8249. [1]: https://github.com/eclipse-apoapsis/ort-server Signed-off-by: Martin Nonnenmacher --- .../src/main/kotlin/ort-kotlin-conventions.gradle.kts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts b/buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts index 59f51b87ce882..c23b9f50b64b2 100644 --- a/buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts @@ -111,8 +111,9 @@ detekt { } val javaVersion = JavaVersion.current() -val maxKotlinJvmTarget = runCatching { JvmTarget.fromTarget(javaVersion.majorVersion) } +val jvmSourceCompatibility = runCatching { JvmTarget.fromTarget(javaVersion.majorVersion) } .getOrDefault(enumValues().max()) +val jvmTargetCompatibility = JvmTarget.JVM_11 val mergeDetektReportsTaskName = "mergeDetektReports" val mergeDetektReports = if (rootProject.tasks.findByName(mergeDetektReportsTaskName) != null) { @@ -124,7 +125,7 @@ val mergeDetektReports = if (rootProject.tasks.findByName(mergeDetektReportsTask } tasks.withType().configureEach detekt@{ - jvmTarget = maxKotlinJvmTarget.target + jvmTarget = jvmTargetCompatibility.target dependsOn(":detekt-rules:assemble") @@ -154,8 +155,8 @@ tasks.withType().configureEach detekt@{ tasks.withType().configureEach { // Align this with Kotlin to avoid errors, see https://youtrack.jetbrains.com/issue/KT-48745. - sourceCompatibility = maxKotlinJvmTarget.target - targetCompatibility = maxKotlinJvmTarget.target + sourceCompatibility = jvmSourceCompatibility.target + targetCompatibility = jvmTargetCompatibility.target } tasks.withType().configureEach { @@ -172,7 +173,7 @@ tasks.withType().configureEach { compilerOptions { allWarningsAsErrors = true freeCompilerArgs.addAll(customCompilerArgs) - jvmTarget = maxKotlinJvmTarget + jvmTarget = jvmTargetCompatibility } }