From 1fece957cb2372cb0d0227a03f082eb982f44b88 Mon Sep 17 00:00:00 2001 From: Jendrik Johannes Date: Tue, 7 May 2024 08:09:13 +0200 Subject: [PATCH] chore: require a fixed 'major.minor.patch' Java version to be installed Signed-off-by: Jendrik Johannes --- .../com.hedera.hashgraph.java.gradle.kts | 36 ++++++------------- build-logic/settings-plugins/build.gradle.kts | 5 +-- ...era.hashgraph.settings.settings.gradle.kts | 5 +-- 3 files changed, 13 insertions(+), 33 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 46fc6d6623f2..53777e2156f3 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,33 +38,18 @@ 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." +// Fail the build if Gradle is started with a Java version that does not exactly match +val javaVersion = "21.0.1" +val currentJavaVersion = providers.systemProperty("java.version").get() + +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 = MIN_JAVA_VERSION - targetCompatibility = MIN_JAVA_VERSION - - toolchain { - languageVersion = JavaLanguageVersion.of(21) - vendor = JvmVendorSpec.ADOPTIUM - } -} - configurations.all { // In case published versions of a module are also available, always prefer the local one resolutionStrategy.preferProjectModules() @@ -144,9 +129,10 @@ tasks.withType().configureEach { // By default, Gradle only tracks the major version as defined in the toolchain (e.g. 17). // Since the full version is encoded in 'module-info.class' files, it should be tracked as // it otherwise leads to wrong build cache hits. - inputs.property("fullJavaVersion", providers.systemProperty("java.version")) + inputs.property("fullJavaVersion", currentJavaVersion) options.encoding = "UTF-8" + options.isFork = true // run compiler in separate JVM process (independent of toolchain setup) doLast { // Make sure consistent line ending are used in files generated by annotation processors by diff --git a/build-logic/settings-plugins/build.gradle.kts b/build-logic/settings-plugins/build.gradle.kts index 01de7ec67381..ed01f04e8034 100644 --- a/build-logic/settings-plugins/build.gradle.kts +++ b/build-logic/settings-plugins/build.gradle.kts @@ -16,7 +16,4 @@ plugins { `kotlin-dsl` } -dependencies { - implementation("org.gradle.toolchains:foojay-resolver:0.7.0") - implementation("com.gradle:gradle-enterprise-gradle-plugin:3.15.1") -} +dependencies { implementation("com.gradle:gradle-enterprise-gradle-plugin:3.15.1") } diff --git a/build-logic/settings-plugins/src/main/kotlin/com.hedera.hashgraph.settings.settings.gradle.kts b/build-logic/settings-plugins/src/main/kotlin/com.hedera.hashgraph.settings.settings.gradle.kts index 51c95581c1f4..fc59f64dfb39 100644 --- a/build-logic/settings-plugins/src/main/kotlin/com.hedera.hashgraph.settings.settings.gradle.kts +++ b/build-logic/settings-plugins/src/main/kotlin/com.hedera.hashgraph.settings.settings.gradle.kts @@ -22,10 +22,7 @@ pluginManagement { } } -plugins { - id("com.gradle.enterprise") - id("org.gradle.toolchains.foojay-resolver-convention") -} +plugins { id("com.gradle.enterprise") } // Enable Gradle Build Scan gradleEnterprise {