Skip to content

Commit

Permalink
Check for Java 17 toolchain and fail if not found (#6303)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
Co-authored-by: Jack Berg <jberg@newrelic.com>
  • Loading branch information
bogdandrutu and jack-berg authored Mar 21, 2024
1 parent 44c69ea commit d8f26b2
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ plugins {
id("com.diffplug.spotless") version "6.25.0"
}

if (!JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) {
if (!hasLauncherForJavaVersion(17)) {
throw GradleException(
"JDK 17 or higher is required to build. " +
"One option is to download it from https://adoptium.net/. If you believe you already " +
"have it, please check that the JAVA_HOME environment variable is pointing at the " +
"JDK 17 installation.",
"JDK 17 is required to build and gradle was unable to detect it on the system. " +
"Please install it and see https://docs.gradle.org/current/userguide/toolchains.html#sec:auto_detection " +
"for details on how gradle detects java toolchains."
)
}

fun hasLauncherForJavaVersion(version: Int): Boolean {
return try {
javaToolchains.launcherFor { languageVersion = JavaLanguageVersion.of(version) }.get()
true
} catch (e: Exception) {
false
}
}

spotless {
kotlinGradle {
ktlint().editorConfigOverride(mapOf(
Expand Down

0 comments on commit d8f26b2

Please sign in to comment.