diff --git a/build-logic/project-plugins/src/main/kotlin/com.hedera.hashgraph.java.gradle.kts b/build-logic/project-plugins/src/main/kotlin/com.hedera.hashgraph.java.gradle.kts index 70eca7642b48..46fc6d6623f2 100644 --- a/build-logic/project-plugins/src/main/kotlin/com.hedera.hashgraph.java.gradle.kts +++ b/build-logic/project-plugins/src/main/kotlin/com.hedera.hashgraph.java.gradle.kts @@ -38,9 +38,26 @@ plugins { version = providers.fileContents(rootProject.layout.projectDirectory.versionTxt()).asText.get().trim() +// Fail the build if Gradle is started with an old version of Java +val MIN_JAVA_VERSION = JavaVersion.VERSION_21 +val CUR_JAVA_VERSION = JavaVersion.current() + +if (CUR_JAVA_VERSION.ordinal < MIN_JAVA_VERSION.ordinal) { + throw StopExecutionException( + "ERROR: Gradle is started with Java " + + CUR_JAVA_VERSION + + ". This project requires running Gradle with Java " + + MIN_JAVA_VERSION + + " or above." + + " Please check your JAVA_HOME and/or PATH and configure the default JDK to use Java version " + + MIN_JAVA_VERSION + + " or above." + ) +} + java { - sourceCompatibility = JavaVersion.VERSION_21 - targetCompatibility = JavaVersion.VERSION_21 + sourceCompatibility = MIN_JAVA_VERSION + targetCompatibility = MIN_JAVA_VERSION toolchain { languageVersion = JavaLanguageVersion.of(21)