From fc62ea65ae2067f7cb2e4e833fb14b4a5b5f4877 Mon Sep 17 00:00:00 2001 From: Mark Vieira Date: Wed, 13 Oct 2021 16:02:47 -0700 Subject: [PATCH] Separate minimum compiler and runtime Java version properties --- .../VersionPropertiesBuildService.java | 19 +++++++++++++------ build-tools-internal/build.gradle | 9 +-------- build-tools/build.gradle | 5 ++--- build-tools/reaper/build.gradle | 4 ++-- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/VersionPropertiesBuildService.java b/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/VersionPropertiesBuildService.java index 92f7848e80deb..adc25dec5e07f 100644 --- a/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/VersionPropertiesBuildService.java +++ b/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/VersionPropertiesBuildService.java @@ -15,13 +15,11 @@ import org.gradle.api.provider.ProviderFactory; import org.gradle.api.services.BuildService; import org.gradle.api.services.BuildServiceParameters; -import org.gradle.initialization.layout.BuildLayout; -import org.gradle.initialization.layout.BuildLayoutFactory; -import javax.inject.Inject; import java.io.File; import java.io.IOException; import java.util.Properties; +import javax.inject.Inject; abstract class VersionPropertiesBuildService implements BuildService, AutoCloseable { @@ -33,15 +31,24 @@ public VersionPropertiesBuildService(ProviderFactory providerFactory) { try { File propertiesInputFile = new File(infoPath, "version.properties"); properties = VersionPropertiesLoader.loadBuildSrcVersion(propertiesInputFile, providerFactory); - properties.computeIfAbsent("minimumJava", s -> resolveMinimumJavaVersion(infoPath)); + properties.computeIfAbsent("minimumRuntimeJava", s -> resolveMinimumRuntimeJavaVersion(infoPath)); + properties.computeIfAbsent("minimumCompilerJava", s -> resolveMinimumCompilerJavaVersion(infoPath)); } catch (IOException e) { throw new GradleException("Cannot load VersionPropertiesBuildService", e); } } - private JavaVersion resolveMinimumJavaVersion(File infoPath) { + private JavaVersion resolveMinimumRuntimeJavaVersion(File infoPath) { + return resolveJavaVersion(infoPath, "src/main/resources/minimumRuntimeVersion"); + } + + private JavaVersion resolveMinimumCompilerJavaVersion(File infoPath) { + return resolveJavaVersion(infoPath, "src/main/resources/minimumCompilerVersion"); + } + + private JavaVersion resolveJavaVersion(File infoPath, String path) { final JavaVersion minimumJavaVersion; - File minimumJavaInfoSource = new File(infoPath, "src/main/resources/minimumRuntimeVersion"); + File minimumJavaInfoSource = new File(infoPath, path); try { String versionString = FileUtils.readFileToString(minimumJavaInfoSource); minimumJavaVersion = JavaVersion.toVersion(versionString); diff --git a/build-tools-internal/build.gradle b/build-tools-internal/build.gradle index 33046d6097c80..2bb0e923497e6 100644 --- a/build-tools-internal/build.gradle +++ b/build-tools-internal/build.gradle @@ -6,13 +6,6 @@ * Side Public License, v 1. */ - -import org.elasticsearch.gradle.internal.conventions.VersionPropertiesLoader -import org.apache.tools.ant.taskdefs.condition.Os -import org.gradle.plugins.ide.eclipse.model.AccessRule -import org.gradle.plugins.ide.eclipse.model.SourceFolder -import org.gradle.plugins.ide.eclipse.model.ProjectDependency - plugins { id 'java-gradle-plugin' id 'groovy-gradle-plugin' @@ -169,7 +162,7 @@ gradlePlugin { * Java version * *****************************************************************************/ -def minCompilerJava = versions.get("minimumJava") +def minCompilerJava = versions.get("minimumCompilerJava") targetCompatibility = minCompilerJava sourceCompatibility = minCompilerJava diff --git a/build-tools/build.gradle b/build-tools/build.gradle index 5ee1e777cb7d8..6ad59c1b4ed3f 100644 --- a/build-tools/build.gradle +++ b/build-tools/build.gradle @@ -5,7 +5,6 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ -import org.elasticsearch.gradle.internal.conventions.VersionPropertiesLoader plugins { id 'java-gradle-plugin' @@ -21,8 +20,8 @@ description = "The elasticsearch build tools" group = "org.elasticsearch.gradle" version = versions.getProperty("elasticsearch") -targetCompatibility = versions.get("minimumJava") -sourceCompatibility = versions.get("minimumJava") +targetCompatibility = versions.get("minimumRuntimeJava") +sourceCompatibility = versions.get("minimumRuntimeJava") gradlePlugin { // We already configure publication and we don't need or want the one that comes diff --git a/build-tools/reaper/build.gradle b/build-tools/reaper/build.gradle index 90a82aac3eb95..42f2826575515 100644 --- a/build-tools/reaper/build.gradle +++ b/build-tools/reaper/build.gradle @@ -6,8 +6,8 @@ plugins { group = "org.elasticsearch.gradle" version = versions.getProperty("elasticsearch") -targetCompatibility = versions.get("minimumJava") -sourceCompatibility = versions.get("minimumJava") +targetCompatibility = versions.get("minimumRuntimeJava") +sourceCompatibility = versions.get("minimumRuntimeJava") tasks.named("jar").configure { archiveFileName = "${project.name}.jar"