-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Update build to use gradle wrapper 6.8 #65596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bc7440a
9a60a22
31fdbaa
39cf274
757d507
e99d42b
e77944f
0b61e3e
0292688
a38d5b9
e8a9afa
3dd4234
bbc37af
eae583b
d3611f3
f2dd4c3
1e50f5d
77dbe62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,12 +28,12 @@ | |
import org.gradle.api.Project; | ||
import org.gradle.api.logging.Logger; | ||
import org.gradle.api.logging.Logging; | ||
import org.gradle.api.model.ObjectFactory; | ||
import org.gradle.api.provider.Provider; | ||
import org.gradle.api.provider.ProviderFactory; | ||
import org.gradle.internal.jvm.Jvm; | ||
import org.gradle.jvm.toolchain.JavaInstallation; | ||
import org.gradle.jvm.toolchain.JavaInstallationRegistry; | ||
import org.gradle.internal.jvm.inspection.JvmInstallationMetadata; | ||
import org.gradle.internal.jvm.inspection.JvmMetadataDetector; | ||
import org.gradle.jvm.toolchain.internal.InstallationLocation; | ||
import org.gradle.jvm.toolchain.internal.SharedJavaInstallationRegistry; | ||
import org.gradle.util.GradleVersion; | ||
|
||
import javax.inject.Inject; | ||
|
@@ -50,7 +50,6 @@ | |
import java.nio.file.Paths; | ||
import java.time.ZoneOffset; | ||
import java.time.ZonedDateTime; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
|
@@ -68,14 +67,18 @@ public class GlobalBuildInfoPlugin implements Plugin<Project> { | |
private static final String DEFAULT_VERSION_JAVA_FILE_PATH = "server/src/main/java/org/elasticsearch/Version.java"; | ||
private static Integer _defaultParallel = null; | ||
|
||
private final JavaInstallationRegistry javaInstallationRegistry; | ||
private final ObjectFactory objects; | ||
private final SharedJavaInstallationRegistry javaInstallationRegistry; | ||
private final JvmMetadataDetector metadataDetector; | ||
private final ProviderFactory providers; | ||
|
||
@Inject | ||
public GlobalBuildInfoPlugin(JavaInstallationRegistry javaInstallationRegistry, ObjectFactory objects, ProviderFactory providers) { | ||
public GlobalBuildInfoPlugin( | ||
SharedJavaInstallationRegistry javaInstallationRegistry, | ||
JvmMetadataDetector metadataDetector, | ||
ProviderFactory providers | ||
) { | ||
this.javaInstallationRegistry = javaInstallationRegistry; | ||
this.objects = objects; | ||
this.metadataDetector = metadataDetector; | ||
this.providers = providers; | ||
} | ||
|
||
|
@@ -105,8 +108,8 @@ public void apply(Project project) { | |
params.setRuntimeJavaHome(runtimeJavaHome); | ||
params.setRuntimeJavaVersion(determineJavaVersion("runtime java.home", runtimeJavaHome, minimumRuntimeVersion)); | ||
params.setIsRutimeJavaHomeSet(Jvm.current().getJavaHome().equals(runtimeJavaHome) == false); | ||
params.setRuntimeJavaDetails(getJavaInstallation(runtimeJavaHome).getImplementationName()); | ||
params.setJavaVersions(getAvailableJavaVersions(minimumCompilerVersion)); | ||
params.setRuntimeJavaDetails(getJavaInstallation(runtimeJavaHome).getDisplayName()); | ||
params.setJavaVersions(getAvailableJavaVersions()); | ||
params.setMinimumCompilerVersion(minimumCompilerVersion); | ||
params.setMinimumRuntimeVersion(minimumRuntimeVersion); | ||
params.setGradleJavaVersion(Jvm.current().getJavaVersion()); | ||
|
@@ -146,20 +149,22 @@ private void logGlobalBuildInfo() { | |
final String osVersion = System.getProperty("os.version"); | ||
final String osArch = System.getProperty("os.arch"); | ||
final Jvm gradleJvm = Jvm.current(); | ||
final String gradleJvmDetails = getJavaInstallation(gradleJvm.getJavaHome()).getImplementationName(); | ||
|
||
JvmInstallationMetadata gradleJvmMetadata = metadataDetector.getMetadata(gradleJvm.getJavaHome()); | ||
final String gradleJvmVendorDetails = gradleJvmMetadata.getVendor().getDisplayName(); | ||
LOGGER.quiet("======================================="); | ||
LOGGER.quiet("Elasticsearch Build Hamster says Hello!"); | ||
LOGGER.quiet(" Gradle Version : " + GradleVersion.current().getVersion()); | ||
LOGGER.quiet(" OS Info : " + osName + " " + osVersion + " (" + osArch + ")"); | ||
if (BuildParams.getIsRuntimeJavaHomeSet()) { | ||
String runtimeJvmDetails = getJavaInstallation(BuildParams.getRuntimeJavaHome()).getImplementationName(); | ||
LOGGER.quiet(" Runtime JDK Version : " + BuildParams.getRuntimeJavaVersion() + " (" + runtimeJvmDetails + ")"); | ||
final String runtimeJvmVendorDetails = metadataDetector.getMetadata(BuildParams.getRuntimeJavaHome()) | ||
.getVendor() | ||
.getDisplayName(); | ||
LOGGER.quiet(" Runtime JDK Version : " + BuildParams.getRuntimeJavaVersion() + " (" + runtimeJvmVendorDetails + ")"); | ||
LOGGER.quiet(" Runtime java.home : " + BuildParams.getRuntimeJavaHome()); | ||
LOGGER.quiet(" Gradle JDK Version : " + gradleJvm.getJavaVersion() + " (" + gradleJvmDetails + ")"); | ||
LOGGER.quiet(" Gradle JDK Version : " + gradleJvm.getJavaVersion() + " (" + gradleJvmVendorDetails + ")"); | ||
LOGGER.quiet(" Gradle java.home : " + gradleJvm.getJavaHome()); | ||
} else { | ||
LOGGER.quiet(" JDK Version : " + gradleJvm.getJavaVersion() + " (" + gradleJvmDetails + ")"); | ||
LOGGER.quiet(" JDK Version : " + gradleJvm.getJavaVersion() + " (" + gradleJvmVendorDetails + ")"); | ||
LOGGER.quiet(" JAVA_HOME : " + gradleJvm.getJavaHome()); | ||
} | ||
LOGGER.quiet(" Random Testing Seed : " + BuildParams.getTestSeed()); | ||
|
@@ -168,8 +173,8 @@ private void logGlobalBuildInfo() { | |
} | ||
|
||
private JavaVersion determineJavaVersion(String description, File javaHome, JavaVersion requiredVersion) { | ||
JavaInstallation installation = getJavaInstallation(javaHome); | ||
JavaVersion actualVersion = installation.getJavaVersion(); | ||
InstallationLocation installation = getJavaInstallation(javaHome); | ||
JavaVersion actualVersion = metadataDetector.getMetadata(installation.getLocation()).getLanguageVersion(); | ||
if (actualVersion.isCompatibleWith(requiredVersion) == false) { | ||
throwInvalidJavaHomeException( | ||
description, | ||
|
@@ -182,46 +187,33 @@ private JavaVersion determineJavaVersion(String description, File javaHome, Java | |
return actualVersion; | ||
} | ||
|
||
private JavaInstallation getJavaInstallation(File javaHome) { | ||
JavaInstallation installation; | ||
if (isCurrentJavaHome(javaHome)) { | ||
installation = javaInstallationRegistry.getInstallationForCurrentVirtualMachine().get(); | ||
} else { | ||
installation = javaInstallationRegistry.installationForDirectory(objects.directoryProperty().fileValue(javaHome)).get(); | ||
} | ||
|
||
return installation; | ||
private InstallationLocation getJavaInstallation(File javaHome) { | ||
return javaInstallationRegistry.listInstallations() | ||
.stream() | ||
.filter(installationLocation -> isSameFile(javaHome, installationLocation)) | ||
.findFirst() | ||
.get(); | ||
} | ||
|
||
private List<JavaHome> getAvailableJavaVersions(JavaVersion minimumCompilerVersion) { | ||
final List<JavaHome> javaVersions = new ArrayList<>(); | ||
for (int v = 8; v <= Integer.parseInt(minimumCompilerVersion.getMajorVersion()); v++) { | ||
int version = v; | ||
String javaHomeEnvVarName = getJavaHomeEnvVarName(Integer.toString(version)); | ||
if (System.getenv(javaHomeEnvVarName) != null) { | ||
File javaHomeDirectory = new File(findJavaHome(Integer.toString(version))); | ||
Provider<JavaInstallation> javaInstallationProvider = javaInstallationRegistry.installationForDirectory( | ||
objects.directoryProperty().fileValue(javaHomeDirectory) | ||
); | ||
JavaHome javaHome = JavaHome.of(version, providers.provider(() -> { | ||
int actualVersion = Integer.parseInt(javaInstallationProvider.get().getJavaVersion().getMajorVersion()); | ||
if (actualVersion != version) { | ||
throwInvalidJavaHomeException("env variable " + javaHomeEnvVarName, javaHomeDirectory, version, actualVersion); | ||
} | ||
return javaHomeDirectory; | ||
})); | ||
javaVersions.add(javaHome); | ||
} | ||
private boolean isSameFile(File javaHome, InstallationLocation installationLocation) { | ||
try { | ||
return Files.isSameFile(installationLocation.getLocation().toPath(), javaHome.toPath()); | ||
} catch (IOException ioException) { | ||
throw new UncheckedIOException(ioException); | ||
} | ||
return javaVersions; | ||
} | ||
|
||
private static boolean isCurrentJavaHome(File javaHome) { | ||
try { | ||
return Files.isSameFile(javaHome.toPath(), Jvm.current().getJavaHome().toPath()); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
/** | ||
* We resolve all available java versions using auto detected by gradles tool chain | ||
* To make transition more reliable we only take env var provided installations into account for now | ||
*/ | ||
private List<JavaHome> getAvailableJavaVersions() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The bit we lose here is that we no longer enorce that the environment variable name matches the JDK version it points at. I guess this would later fail w/ us not being able to resovle a compatible JDK. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point. is that something you think is worth to invest in? I guess those issues are rare, but when they occur they suck to be debugged I can imagine. Maybe we want to look into this safety net in a follow up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think realistically what we want to do is remove the reliance on these environment variables and use Gradle's toolchain capabilities to just download a compatible JDK when necessary. These variables are only used for build time purposes, where we intend to run tests with a particular JDK implementation, that's what RUNTIME_JAVA_HOME is for. So I think we can punt here and instead focus on ditching all usages of these things vs resolving JDKs dynamically. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will look into this in a separate PR. I didn't want to make too many changes in this PR. So There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem I see at the moment is that the compatibility choices (which vendor is available etc.) is limited in gradle at the moment and might not be enough. If you say that's less of an issue for |
||
return javaInstallationRegistry.listInstallations().stream().map(installationLocation -> { | ||
File installationDir = installationLocation.getLocation(); | ||
JvmInstallationMetadata metadata = metadataDetector.getMetadata(installationDir); | ||
int actualVersion = Integer.parseInt(metadata.getLanguageVersion().getMajorVersion()); | ||
return JavaHome.of(actualVersion, providers.provider(() -> installationDir)); | ||
}).collect(Collectors.toList()); | ||
} | ||
|
||
private static String getTestSeed() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,9 @@ public class JarHellPrecommitPlugin extends PrecommitPlugin { | |
public TaskProvider<? extends Task> createTask(Project project) { | ||
Configuration jarHellConfig = project.getConfigurations().create("jarHell"); | ||
if (BuildParams.isInternal() && project.getPath().equals(":libs:elasticsearch-core") == false) { | ||
// ideally we would configure this as a default dependency. But Default dependencies do not work correctly | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's fine anyway as we don't expect this to be replaced. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other question though. How does this work for external builds? Where does the jarhell implementation come from? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You would need to add a dependency like `jarHell 'org.elasticsearch:elasticsearch-core:7.10' at the moment. In general I think we need to put some more dedicated effort into making these external available plugins work nicely for contributors. By that I mean having proper test coverage of third party plugin author use cases etc. I remember we talked about that very early on when having our first talks about the elastic build already. |
||
// with gradle project dependencies as they're resolved to late in the build and don't setup according task | ||
// dependencies properly | ||
project.getDependencies().add("jarHell", project.project(":libs:elasticsearch-core")); | ||
} | ||
TaskProvider<JarHellTask> jarHell = project.getTasks().register("jarHell", JarHellTask.class); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to keep this here or was this only for testing? I'm ok with keeping this around across the board BTW.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep it.