From 4f8da08a8f2ca4a62af441e9edb18e25e744e4e6 Mon Sep 17 00:00:00 2001 From: Anthony Petrov Date: Fri, 12 Apr 2024 10:35:37 -0700 Subject: [PATCH 1/4] feat(build): fail if Gradle is started with Java 20 or older Signed-off-by: Anthony Petrov --- settings.gradle.kts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/settings.gradle.kts b/settings.gradle.kts index 73b607b22a78..450842ce1011 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -160,3 +160,14 @@ dependencyResolutionManagement { plugin("pbj", "com.hedera.pbj.pbj-compiler").version("0.8.5") } } + +// 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) { + System.err.println("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."); + System.exit(1); +} From 9a19fddacaf78df748937c80630d80a9ed3fdfdb Mon Sep 17 00:00:00 2001 From: Anthony Petrov Date: Fri, 12 Apr 2024 10:52:55 -0700 Subject: [PATCH 2/4] move the logic from settings to java.gradle.kts Signed-off-by: Anthony Petrov --- .../kotlin/com.hedera.hashgraph.java.gradle.kts | 15 +++++++++++++-- settings.gradle.kts | 11 ----------- 2 files changed, 13 insertions(+), 13 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 70eca7642b48..17fdc290be78 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,20 @@ 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) { + System.err.println("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."); + System.exit(1); +} + java { - sourceCompatibility = JavaVersion.VERSION_21 - targetCompatibility = JavaVersion.VERSION_21 + sourceCompatibility = MIN_JAVA_VERSION + targetCompatibility = MIN_JAVA_VERSION toolchain { languageVersion = JavaLanguageVersion.of(21) diff --git a/settings.gradle.kts b/settings.gradle.kts index 450842ce1011..73b607b22a78 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -160,14 +160,3 @@ dependencyResolutionManagement { plugin("pbj", "com.hedera.pbj.pbj-compiler").version("0.8.5") } } - -// 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) { - System.err.println("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."); - System.exit(1); -} From 92a9ea99c01b29f2b66c66d7e2eed9ea2fed9beb Mon Sep 17 00:00:00 2001 From: Anthony Petrov Date: Fri, 12 Apr 2024 11:03:22 -0700 Subject: [PATCH 3/4] replace System.exit with throw StopExecutionException Signed-off-by: Anthony Petrov --- .../src/main/kotlin/com.hedera.hashgraph.java.gradle.kts | 3 +-- 1 file changed, 1 insertion(+), 2 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 17fdc290be78..f914e35f64dd 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 @@ -42,11 +42,10 @@ version = val MIN_JAVA_VERSION = JavaVersion.VERSION_21 val CUR_JAVA_VERSION = JavaVersion.current() if (CUR_JAVA_VERSION.ordinal < MIN_JAVA_VERSION.ordinal) { - System.err.println("ERROR: Gradle is started with Java " + CUR_JAVA_VERSION + 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."); - System.exit(1); } java { From c7e950d24778c119b2f8c51fa6847ba0af1cdc88 Mon Sep 17 00:00:00 2001 From: Anthony Petrov Date: Fri, 12 Apr 2024 11:56:01 -0700 Subject: [PATCH 4/4] spotless Signed-off-by: Anthony Petrov --- .../kotlin/com.hedera.hashgraph.java.gradle.kts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 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 f914e35f64dd..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 @@ -41,11 +41,18 @@ version = // 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."); + 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 {