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 c925e53adff9..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,31 +38,29 @@ 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." - ) +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") + } } java { - sourceCompatibility = MIN_JAVA_VERSION - targetCompatibility = MIN_JAVA_VERSION - - toolchain { - languageVersion = JavaLanguageVersion.of(21) - vendor = JvmVendorSpec.ADOPTIUM - } + sourceCompatibility = javaVersionMajor + targetCompatibility = javaVersionMajor } configurations.all { @@ -148,9 +146,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 {