Skip to content

Commit

Permalink
Check for java 17 launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-berg committed Mar 21, 2024
1 parent 8ca11c3 commit c961087
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() != JavaVersion.VERSION_17) {
if (!hasLauncherForJavaVersion(17)) {
throw GradleException(
"JDK 17 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 c961087

Please sign in to comment.