Skip to content

Commit

Permalink
build: Set the target JVM to 11
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mnonnenmacher committed Mar 12, 2024
1 parent 9935f31 commit 4515c14
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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<JvmTarget>().max())
val jvmTargetCompatibility = JvmTarget.JVM_11

val mergeDetektReportsTaskName = "mergeDetektReports"
val mergeDetektReports = if (rootProject.tasks.findByName(mergeDetektReportsTaskName) != null) {
Expand All @@ -124,7 +125,7 @@ val mergeDetektReports = if (rootProject.tasks.findByName(mergeDetektReportsTask
}

tasks.withType<Detekt>().configureEach detekt@{
jvmTarget = maxKotlinJvmTarget.target
jvmTarget = jvmTargetCompatibility.target

dependsOn(":detekt-rules:assemble")

Expand Down Expand Up @@ -154,8 +155,8 @@ tasks.withType<Detekt>().configureEach detekt@{

tasks.withType<JavaCompile>().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<KotlinCompile>().configureEach {
Expand All @@ -172,7 +173,7 @@ tasks.withType<KotlinCompile>().configureEach {
compilerOptions {
allWarningsAsErrors = true
freeCompilerArgs.addAll(customCompilerArgs)
jvmTarget = maxKotlinJvmTarget
jvmTarget = jvmTargetCompatibility
}
}

Expand Down

0 comments on commit 4515c14

Please sign in to comment.