Skip to content

Commit

Permalink
[7.17] Update Gradle Wrapper to 8.2 (#96686) (#97484)
Browse files Browse the repository at this point in the history
* Update Gradle Wrapper to 8.2 (#96686)

- Convention usage has been deprecated and was fixed in our build files
- Fix test dependencies and deprecation
  • Loading branch information
breskeby committed Sep 27, 2023
1 parent 4bec040 commit 5afd06a
Show file tree
Hide file tree
Showing 100 changed files with 648 additions and 206 deletions.
9 changes: 7 additions & 2 deletions benchmarks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ import org.elasticsearch.gradle.internal.info.BuildParams

apply plugin: 'elasticsearch.java'
apply plugin: 'application'
mainClassName = 'org.openjdk.jmh.Main'

application {
mainClass = 'org.openjdk.jmh.Main'
}

tasks.named("assemble").configure { enabled = false }
archivesBaseName = 'elasticsearch-benchmarks'
base {
archivesName = 'elasticsearch-benchmarks'
}

tasks.named("test").configure { enabled = false }

Expand Down
8 changes: 5 additions & 3 deletions build-conventions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ plugins {
}

group = "org.elasticsearch"

targetCompatibility = 11
sourceCompatibility = 11
// This project contains Checkstyle rule implementations used by IDEs which use a Java 11 runtime
java {
targetCompatibility = 11
sourceCompatibility = 11
}

gradlePlugin {
// We already configure publication and we don't need or want the one that comes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.file.FileTree;
import org.gradle.api.initialization.IncludedBuild;
import org.gradle.api.invocation.Gradle;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.util.PatternFilterable;

import javax.annotation.Nullable;
import java.io.File;
import java.util.Collection;
import java.util.Optional;
import java.util.function.Supplier;

Expand Down Expand Up @@ -102,7 +106,6 @@ private static boolean isJavaExtensionAvailable(Project project) {
return project.getExtensions().getByType(JavaPluginExtension.class) == null;
}


public static Object toStringable(Supplier<String> getter) {
return new Object() {
@Override
Expand All @@ -116,4 +119,31 @@ public static SourceSetContainer getJavaSourceSets(Project project) {
return project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
}

public static File locateElasticsearchWorkspace(Gradle gradle) {
if(gradle.getRootProject().getName().startsWith("build-tools")) {
File buildToolsParent = gradle.getRootProject().getRootDir().getParentFile();
if(versionFileExists(buildToolsParent)) {
return buildToolsParent;
}
return buildToolsParent;
}
if (gradle.getParent() == null) {
// See if any of these included builds is the Elasticsearch gradle
for (IncludedBuild includedBuild : gradle.getIncludedBuilds()) {
if (versionFileExists(includedBuild.getProjectDir())) {
return includedBuild.getProjectDir();
}
}

// Otherwise assume this gradle is the root elasticsearch workspace
return gradle.getRootProject().getRootDir();
} else {
// We're an included build, so keep looking
return locateElasticsearchWorkspace(gradle.getParent());
}
}

private static boolean versionFileExists(File rootDir) {
return new File(rootDir, "build-tools-internal/version.properties").exists();
}
}
7 changes: 4 additions & 3 deletions build-tools-internal/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,10 @@ gradlePlugin {
*****************************************************************************/

def minCompilerJava = versions.get("minimumCompilerJava")
targetCompatibility = minCompilerJava
sourceCompatibility = minCompilerJava
java {
targetCompatibility = minCompilerJava
sourceCompatibility = minCompilerJava
}

if (JavaVersion.current() < JavaVersion.toVersion(minCompilerJava)) {
throw new GradleException("Java ${minCompilerJava} is required to build Elasticsearch but current Java is version ${JavaVersion.current()}.")
Expand Down Expand Up @@ -241,7 +243,6 @@ dependencies {
api buildLibs.commons.codec
api buildLibs.apache.compress
api buildLibs.ant
api 'com.netflix.nebula:gradle-extra-configurations-plugin:7.0.0'
api buildLibs.nebula.info
api buildLibs.apache.rat
api buildLibs.jna
Expand Down
8 changes: 5 additions & 3 deletions build-tools-internal/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
distributionSha256Sum=5022b0b25fe182b0e50867e77f484501dba44feeea88f5c1f13b6b4660463640
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionSha256Sum=db9c8211ed63f61f60292c69e80d89196f9eb36665e369e7f00ac4cc841c2219
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ subprojects {
archiveVersion.set("${versionFromBranch}-SNAPSHOT")
archiveClassifier.set("darwin-x86_64")
archiveExtension.set('tar.gz')
exclude('build')
}

tasks.register('extracted', Copy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ configure(allprojects) {
}
project.tasks.withType(Test).configureEach { Test test ->
if (BuildParams.getIsRuntimeJavaHomeSet()) {
test.executable = "${BuildParams.runtimeJavaHome}/bin/java"
test.executable = "${BuildParams.runtimeJavaHome}/bin/java" +
(OS.current() == OS.WINDOWS ? '.exe' : '')
} else {
test.dependsOn(project.jdks.provisioned_runtime)
test.executable = project.jdks.provisioned_runtime.getBinJavaPath()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ public void apply(Project project) {
var withShadowPlugin = project1.getPlugins().hasPlugin(ShadowPlugin.class);
var compileClasspath = project.getConfigurations().getByName("compileClasspath");

var copiedCompileClasspath = project.getConfigurations().create("copiedCompileClasspath");
copiedCompileClasspath.extendsFrom(compileClasspath);
if (withShadowPlugin) {
var shadowConfiguration = project.getConfigurations().getByName("shadow");
var shadowedDependencies = shadowConfiguration.getAllDependencies();
var nonShadowedCompileClasspath = compileClasspath.copyRecursive(
var nonShadowedCompileClasspath = copiedCompileClasspath.copyRecursive(
dependency -> shadowedDependencies.contains(dependency) == false
);
configureJavadocForConfiguration(project, false, nonShadowedCompileClasspath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.elasticsearch.gradle.internal;

import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.plugins.BasePluginExtension;
Expand Down Expand Up @@ -40,9 +41,18 @@ public void registerTestArtifactFromSourceSet(SourceSet sourceSet) {

DependencyHandler dependencies = project.getDependencies();
project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
Configuration apiElements = project.getConfigurations().getByName(sourceSet.getApiElementsConfigurationName());
Configuration apiElementsTestArtifacts = project.getConfigurations()
.create(sourceSet.getApiConfigurationName() + "TestArtifacts");
apiElements.extendsFrom(apiElementsTestArtifacts);
Dependency projectDependency = dependencies.create(project);
dependencies.add(sourceSet.getApiElementsConfigurationName(), projectDependency);
dependencies.add(sourceSet.getRuntimeElementsConfigurationName(), projectDependency);
dependencies.add(apiElementsTestArtifacts.getName(), projectDependency);

Configuration runtimeElements = project.getConfigurations().getByName(sourceSet.getRuntimeElementsConfigurationName());
Configuration runtimeElementsTestArtifacts = project.getConfigurations()
.create(sourceSet.getRuntimeElementsConfigurationName() + "TestArtifacts");
runtimeElements.extendsFrom(runtimeElementsTestArtifacts);
dependencies.add(runtimeElementsTestArtifacts.getName(), projectDependency);
});
// PolicyUtil doesn't handle classifier notation well probably.
// Instead of fixing PoliceUtil we stick to the pattern of changing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
package org.elasticsearch.gradle.internal.info;

import org.elasticsearch.gradle.internal.BwcVersions;
import org.gradle.api.Action;
import org.gradle.api.JavaVersion;
import org.gradle.api.Task;
import org.gradle.api.provider.Provider;
import org.gradle.jvm.toolchain.JavaToolchainSpec;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Modifier;
import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.function.Consumer;

import static java.util.Objects.requireNonNull;
Expand All @@ -28,6 +33,7 @@ public class BuildParams {
private static JavaVersion minimumRuntimeVersion;
private static JavaVersion gradleJavaVersion;
private static JavaVersion runtimeJavaVersion;
private static Provider<? extends Action<JavaToolchainSpec>> javaToolChainSpec;
private static String runtimeJavaDetails;
private static Boolean inFipsJvm;
private static String gitRevision;
Expand Down Expand Up @@ -87,6 +93,10 @@ public static Boolean isInFipsJvm() {
return value(inFipsJvm);
}

public static void withFipsEnabledOnly(Task task) {
task.onlyIf("FIPS mode disabled", task1 -> isInFipsJvm() == false);
}

public static String getGitRevision() {
return value(gitRevision);
}
Expand All @@ -107,10 +117,18 @@ public static String getTestSeed() {
return value(testSeed);
}

public static Random getRandom() {
return new Random(Long.parseUnsignedLong(testSeed.split(":")[0], 16));
}

public static Boolean isCi() {
return value(isCi);
}

public static Boolean isGraalVmRuntime() {
return value(runtimeJavaDetails.toLowerCase().contains("graalvm"));
}

public static Integer getDefaultParallel() {
return value(defaultParallel);
}
Expand All @@ -119,6 +137,10 @@ public static boolean isSnapshotBuild() {
return value(BuildParams.isSnapshotBuild);
}

public static Provider<? extends Action<JavaToolchainSpec>> getJavaToolChainSpec() {
return javaToolChainSpec;
}

private static <T> T value(T object) {
if (object == null) {
String callingMethod = Thread.currentThread().getStackTrace()[2].getMethodName();
Expand Down Expand Up @@ -161,7 +183,11 @@ public void reset() {
}

public void setRuntimeJavaHome(File runtimeJavaHome) {
BuildParams.runtimeJavaHome = requireNonNull(runtimeJavaHome);
try {
BuildParams.runtimeJavaHome = requireNonNull(runtimeJavaHome).getCanonicalFile();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public void setIsRuntimeJavaHomeSet(boolean isRutimeJavaHomeSet) {
Expand Down Expand Up @@ -227,5 +253,9 @@ public void setIsSnapshotBuild(final boolean isSnapshotBuild) {
public void setBwcVersions(Provider<BwcVersions> bwcVersions) {
BuildParams.bwcVersions = requireNonNull(bwcVersions);
}

public void setJavaToolChainSpec(Provider<? extends Action<JavaToolchainSpec>> javaToolChain) {
BuildParams.javaToolChainSpec = javaToolChain;
}
}
}

0 comments on commit 5afd06a

Please sign in to comment.