From fbea6a7c192111ff5c8c94b8f87cb533a57c3862 Mon Sep 17 00:00:00 2001 From: Jendrik Johannes Date: Wed, 15 May 2024 08:56:03 +0200 Subject: [PATCH] chore: only warn for Java versions that do not break the build Signed-off-by: Jendrik Johannes --- .../com.hedera.hashgraph.java.gradle.kts | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) 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 b72a0c847b25..e2971c1e4550 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,16 +38,29 @@ plugins { version = providers.fileContents(rootProject.layout.projectDirectory.versionTxt()).asText.get().trim() -// Fail the build if Gradle is started with a Java version that does not exactly match -val javaVersion = "21.0.1" +val javaVersionMajor = JavaVersion.VERSION_21 +val javaVersionPatch = "0.1" + +val currentJavaVersionMajor = JavaVersion.current() val currentJavaVersion = providers.systemProperty("java.version").get() +val expectedJavaVersion = "$javaVersionMajor.$javaVersionPatch" + +if (currentJavaVersion != expectedJavaVersion) { + val message = + "Gradle runs with Java $currentJavaVersion. This project works best running with Java $expectedJavaVersion. " + + "\n - From commandline: change JAVA_HOME and/or PATH to point at Java $expectedJavaVersion installation." + + "\n - From IntelliJ: change 'Gradle JVM' in 'Gradle Settings' to point at Java $expectedJavaVersion installation." + + if (currentJavaVersionMajor.ordinal < javaVersionMajor.ordinal) { // fail if version is too old + throw (RuntimeException(message)) + } else { + logger.lifecycle("WARN: $message") + } +} -if (currentJavaVersion != javaVersion) { - throw RuntimeException( - "Gradle runs with Java $currentJavaVersion. This project requires Gradle to run with Java $javaVersion. " + - "\n - From commandline: change JAVA_HOME and/or PATH to point at Java $javaVersion installation." + - "\n - From IntelliJ: change 'Gradle JVM' in 'Gradle Settings' to point at Java $javaVersion installation." - ) +java { + sourceCompatibility = javaVersionMajor + targetCompatibility = javaVersionMajor } configurations.all {