Skip to content

Commit d8f26b2

Browse files
Check for Java 17 toolchain and fail if not found (#6303)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com> Co-authored-by: Jack Berg <jberg@newrelic.com>
1 parent 44c69ea commit d8f26b2

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

buildSrc/build.gradle.kts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,23 @@ plugins {
55
id("com.diffplug.spotless") version "6.25.0"
66
}
77

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

16+
fun hasLauncherForJavaVersion(version: Int): Boolean {
17+
return try {
18+
javaToolchains.launcherFor { languageVersion = JavaLanguageVersion.of(version) }.get()
19+
true
20+
} catch (e: Exception) {
21+
false
22+
}
23+
}
24+
1725
spotless {
1826
kotlinGradle {
1927
ktlint().editorConfigOverride(mapOf(

0 commit comments

Comments
 (0)