Skip to content

Commit

Permalink
Separate minimum compiler and runtime Java version properties (#79108)
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-vieira authored Oct 14, 2021
1 parent 4717fbb commit 8916213
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<VersionPropertiesBuildService.Params>, AutoCloseable {

Expand All @@ -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);
Expand Down
9 changes: 1 addition & 8 deletions build-tools-internal/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -170,7 +163,7 @@ gradlePlugin {
* Java version *
*****************************************************************************/

def minCompilerJava = versions.get("minimumJava")
def minCompilerJava = versions.get("minimumCompilerJava")
targetCompatibility = minCompilerJava
sourceCompatibility = minCompilerJava

Expand Down
5 changes: 2 additions & 3 deletions build-tools/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -22,8 +21,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
Expand Down
4 changes: 2 additions & 2 deletions build-tools/reaper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,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"
Expand Down

0 comments on commit 8916213

Please sign in to comment.