Skip to content

Commit 1e0b614

Browse files
authored
[7.17] Update Gradle wrapper to 8.8 (#108021) (#109348)
Fix incompatibility with 8.8 and our internal api usages - Update ospackage to a version that contains a fix we provided - Tweak build logic to avoid deprecation warnings - Use newer permission api - Use custom shadowplugin - Rework ElasticsearchDistribution dependencies resolution - Update Gradle wrapper to 8.8 - Fix one more deprecated permission api usage - Fix DistroTest dependencies - Fix permissions in package init.d folder
1 parent 07296d5 commit 1e0b614

32 files changed

+434
-217
lines changed

build-conventions/build.gradle

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88

99
import org.gradle.plugins.ide.eclipse.model.SourceFolder
1010

11+
12+
buildscript {
13+
repositories {
14+
maven {
15+
url 'https://jitpack.io'
16+
}
17+
mavenCentral()
18+
}
19+
}
20+
1121
plugins {
1222
id 'java-gradle-plugin'
1323
id 'java-test-fixtures'
@@ -58,6 +68,10 @@ gradlePlugin {
5868
}
5969

6070
repositories {
71+
maven {
72+
url 'https://jitpack.io'
73+
}
74+
6175
mavenCentral()
6276
gradlePluginPortal()
6377
}

build-tools-internal/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ tasks.named('licenseHeaders').configure {
218218
*****************************************************************************/
219219

220220
repositories {
221+
maven {
222+
url 'https://jitpack.io'
223+
}
221224
mavenCentral()
222225
gradlePluginPortal()
223226
}

build-tools-internal/gradle/wrapper/gradle-wrapper.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionSha256Sum=194717442575a6f96e1c1befa2c30e9a4fc90f701d7aee33eb879b79e7ff05c0
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
3+
distributionSha256Sum=f8b4f4772d302c8ff580bc40d0f56e715de69b163546944f787c87abf209c961
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip
55
networkTimeout=10000
66
validateDistributionUrl=true
77
zipStoreBase=GRADLE_USER_HOME
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
pluginManagement {
2-
includeBuild "../build-conventions"
2+
repositories {
3+
maven {
4+
url 'https://jitpack.io'
5+
}
6+
mavenCentral()
7+
gradlePluginPortal()
8+
}
9+
10+
includeBuild "../build-conventions"
311
includeBuild "../build-tools"
412
}
513

@@ -9,4 +17,4 @@ dependencyResolutionManagement {
917
from(files("../gradle/build.versions.toml"))
1018
}
1119
}
12-
}
20+
}

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionArchiveSetupPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ private void configureGeneralTaskDefaults(Project project) {
9999
project.getTasks().withType(AbstractCopyTask.class).configureEach(t -> {
100100
t.dependsOn(project.getTasks().withType(EmptyDirTask.class));
101101
t.setIncludeEmptyDirs(true);
102-
t.setDirMode(0755);
103-
t.setFileMode(0644);
102+
t.dirPermissions(permissions -> permissions.unix(0755));
103+
t.filePermissions(permissions -> permissions.unix(0644));
104104
});
105105

106106
// common config across all archives

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionDownloadPlugin.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@
2323
import org.elasticsearch.gradle.internal.info.GlobalBuildInfoPlugin;
2424
import org.elasticsearch.gradle.util.GradleUtils;
2525
import org.gradle.api.GradleException;
26-
import org.gradle.api.NamedDomainObjectContainer;
2726
import org.gradle.api.Plugin;
2827
import org.gradle.api.Project;
2928
import org.gradle.api.artifacts.Dependency;
29+
import org.gradle.api.artifacts.dsl.DependencyHandler;
3030
import org.gradle.api.provider.Provider;
3131

32+
import java.util.HashMap;
33+
import java.util.List;
34+
import java.util.Map;
3235
import java.util.function.Function;
3336

34-
import static org.elasticsearch.gradle.util.GradleUtils.projectDependency;
35-
3637
/**
3738
* An internal elasticsearch build plugin that registers additional
3839
* distribution resolution strategies to the 'elasticsearch.download-distribution' plugin
@@ -64,18 +65,18 @@ public void apply(Project project) {
6465
* <p>
6566
* BWC versions are resolved as project to projects under `:distribution:bwc`.
6667
*/
67-
private void registerInternalDistributionResolutions(NamedDomainObjectContainer<DistributionResolution> resolutions) {
68-
resolutions.register("localBuild", distributionResolution -> distributionResolution.setResolver((project, distribution) -> {
69-
if (VersionProperties.getElasticsearch().equals(distribution.getVersion())) {
68+
private void registerInternalDistributionResolutions(List<DistributionResolution> resolutions) {
69+
resolutions.add(new DistributionResolution("local-build", (project, distribution) -> {
70+
if (isCurrentVersion(distribution)) {
7071
// non-external project, so depend on local build
7172
return new ProjectBasedDistributionDependency(
72-
config -> projectDependency(project, distributionProjectPath(distribution), config)
73+
config -> projectDependency(project.getDependencies(), distributionProjectPath(distribution), config)
7374
);
7475
}
7576
return null;
7677
}));
7778

78-
resolutions.register("bwc", distributionResolution -> distributionResolution.setResolver((project, distribution) -> {
79+
resolutions.add(new DistributionResolution("bwc", (project, distribution) -> {
7980
BwcVersions.UnreleasedVersionInfo unreleasedInfo = BuildParams.getBwcVersions()
8081
.unreleasedInfo(Version.fromString(distribution.getVersion()));
8182
if (unreleasedInfo != null) {
@@ -89,13 +90,19 @@ private void registerInternalDistributionResolutions(NamedDomainObjectContainer<
8990
}
9091
String projectConfig = getProjectConfig(distribution, unreleasedInfo);
9192
return new ProjectBasedDistributionDependency(
92-
(config) -> projectDependency(project, unreleasedInfo.gradleProjectPath, projectConfig)
93+
(config) -> projectDependency(project.getDependencies(), unreleasedInfo.gradleProjectPath, projectConfig)
9394
);
9495
}
9596
return null;
9697
}));
9798
}
9899

100+
private boolean isCurrentVersion(ElasticsearchDistribution distribution) {
101+
Version currentVersionNumber = Version.fromString(VersionProperties.getElasticsearch());
102+
Version parsedDistVersionNumber = Version.fromString(distribution.getVersion());
103+
return currentVersionNumber.equals(parsedDistVersionNumber);
104+
}
105+
99106
/**
100107
* Will be removed once this is backported to all unreleased branches.
101108
*/
@@ -110,6 +117,13 @@ private static String getProjectConfig(ElasticsearchDistribution distribution, B
110117
}
111118
}
112119

120+
private static Dependency projectDependency(DependencyHandler dependencyHandler, String projectPath, String projectConfig) {
121+
Map<String, Object> depConfig = new HashMap<>();
122+
depConfig.put("path", projectPath);
123+
depConfig.put("configuration", projectConfig);
124+
return dependencyHandler.project(depConfig);
125+
}
126+
113127
private static String distributionProjectPath(ElasticsearchDistribution distribution) {
114128
String projectPath = ":distribution";
115129
if (distribution.getType() == ElasticsearchDistributionTypes.INTEG_TEST_ZIP) {

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/SymbolicLinkPreservingTar.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private void visitSymbolicLink(final FileCopyDetailsInternal details) {
152152
visitedSymbolicLinks.add(details.getFile());
153153
final TarArchiveEntry entry = new TarArchiveEntry(details.getRelativePath().getPathString(), TarConstants.LF_SYMLINK);
154154
entry.setModTime(getModTime(details));
155-
entry.setMode(UnixStat.LINK_FLAG | details.getMode());
155+
entry.setMode(UnixStat.LINK_FLAG | details.getPermissions().toUnixNumeric());
156156
try {
157157
entry.setLinkName(Files.readSymbolicLink(details.getFile().toPath()).toString());
158158
tar.putArchiveEntry(entry);
@@ -165,7 +165,7 @@ private void visitSymbolicLink(final FileCopyDetailsInternal details) {
165165
private void visitDirectory(final FileCopyDetailsInternal details) {
166166
final TarArchiveEntry entry = new TarArchiveEntry(details.getRelativePath().getPathString() + "/");
167167
entry.setModTime(getModTime(details));
168-
entry.setMode(UnixStat.DIR_FLAG | details.getMode());
168+
entry.setMode(UnixStat.DIR_FLAG | details.getPermissions().toUnixNumeric());
169169
try {
170170
tar.putArchiveEntry(entry);
171171
tar.closeArchiveEntry();
@@ -177,7 +177,7 @@ private void visitDirectory(final FileCopyDetailsInternal details) {
177177
private void visitFile(final FileCopyDetailsInternal details) {
178178
final TarArchiveEntry entry = new TarArchiveEntry(details.getRelativePath().getPathString());
179179
entry.setModTime(getModTime(details));
180-
entry.setMode(UnixStat.FILE_FLAG | details.getMode());
180+
entry.setMode(UnixStat.FILE_FLAG | details.getPermissions().toUnixNumeric());
181181
entry.setSize(details.getSize());
182182
try {
183183
tar.putArchiveEntry(entry);

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/GlobalBuildInfoPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ private List<JavaHome> getAvailableJavaVersions() {
262262
private Stream<InstallationLocation> getAvailableJavaInstallationLocationSteam() {
263263
return Stream.concat(
264264
javaInstallationRegistry.toolchains().stream().map(metadata -> metadata.location),
265-
Stream.of(new InstallationLocation(Jvm.current().getJavaHome(), "Current JVM"))
265+
Stream.of(InstallationLocation.userDefined(Jvm.current().getJavaHome(), "Current JVM"))
266266
);
267267
}
268268

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/DependencyLicensesPrecommitPlugin.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,23 @@
1212
import org.elasticsearch.gradle.internal.conventions.precommit.PrecommitPlugin;
1313
import org.gradle.api.Project;
1414
import org.gradle.api.Task;
15-
import org.gradle.api.artifacts.Configuration;
16-
import org.gradle.api.artifacts.ProjectDependency;
15+
import org.gradle.api.artifacts.component.ComponentIdentifier;
16+
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
1717
import org.gradle.api.plugins.JavaPlugin;
18+
import org.gradle.api.specs.Spec;
1819
import org.gradle.api.tasks.TaskProvider;
1920

2021
public class DependencyLicensesPrecommitPlugin extends PrecommitPlugin {
22+
private static Spec<ComponentIdentifier> COMPONENT_FILTER = identifier -> (identifier instanceof ModuleComponentIdentifier)
23+
&& ((ModuleComponentIdentifier) identifier).getGroup().startsWith("org.elasticsearch") == false;
2124

2225
@Override
2326
public TaskProvider<? extends Task> createTask(Project project) {
2427
project.getPlugins().apply(CompileOnlyResolvePlugin.class);
25-
TaskProvider<DependencyLicensesTask> dependencyLicenses = project.getTasks()
26-
.register("dependencyLicenses", DependencyLicensesTask.class);
27-
28-
// only require dependency licenses for non-elasticsearch deps
29-
dependencyLicenses.configure(t -> {
30-
Configuration runtimeClasspath = project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);
31-
Configuration compileOnly = project.getConfigurations()
32-
.getByName(CompileOnlyResolvePlugin.RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME);
33-
t.setDependencies(
34-
runtimeClasspath.fileCollection(dependency -> dependency instanceof ProjectDependency == false).minus(compileOnly)
35-
);
28+
var dependencyLicenses = project.getTasks().register("dependencyLicenses", DependencyLicensesTask.class, t -> {
29+
var runtimeClasspath = project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);
30+
var compileOnly = project.getConfigurations().getByName(CompileOnlyResolvePlugin.RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME);
31+
t.configureDependencies(runtimeClasspath, compileOnly, COMPONENT_FILTER);
3632
});
3733
return dependencyLicenses;
3834
}

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/DependencyLicensesTask.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@
1111
import org.gradle.api.DefaultTask;
1212
import org.gradle.api.GradleException;
1313
import org.gradle.api.InvalidUserDataException;
14+
import org.gradle.api.artifacts.Configuration;
15+
import org.gradle.api.artifacts.component.ComponentIdentifier;
1416
import org.gradle.api.file.Directory;
1517
import org.gradle.api.file.DirectoryProperty;
1618
import org.gradle.api.file.FileCollection;
1719
import org.gradle.api.file.ProjectLayout;
1820
import org.gradle.api.logging.Logger;
1921
import org.gradle.api.logging.Logging;
2022
import org.gradle.api.model.ObjectFactory;
23+
import org.gradle.api.provider.Property;
2124
import org.gradle.api.provider.Provider;
25+
import org.gradle.api.specs.Spec;
2226
import org.gradle.api.tasks.Input;
2327
import org.gradle.api.tasks.InputDirectory;
2428
import org.gradle.api.tasks.InputFiles;
@@ -41,6 +45,8 @@
4145

4246
import javax.inject.Inject;
4347

48+
import static org.elasticsearch.gradle.internal.util.DependenciesUtils.createFileCollectionFromNonTransitiveArtifactsView;
49+
4450
/**
4551
* A task to check licenses for dependencies.
4652
* <p>
@@ -83,7 +89,7 @@
8389
* for the dependency. This artifact will be redistributed by us with the release to
8490
* comply with the license terms.
8591
*/
86-
public class DependencyLicensesTask extends DefaultTask {
92+
public abstract class DependencyLicensesTask extends DefaultTask {
8793

8894
private final Pattern regex = Pattern.compile("-v?\\d+.*");
8995

@@ -183,6 +189,10 @@ public void ignoreFile(String file) {
183189
ignoreFiles.add(file);
184190
}
185191

192+
@Input
193+
@Optional
194+
public abstract Property<Spec<ComponentIdentifier>> getComponentFilter();
195+
186196
@TaskAction
187197
public void checkDependencies() {
188198
if (dependencies == null) {
@@ -297,7 +307,6 @@ private String getFileName(String name, Map<String, ?> counters, String type) {
297307
// try the other suffix...TODO: get rid of this, just support ending in .txt
298308
return fileName + ".txt";
299309
}
300-
301310
return fileName;
302311
}
303312

@@ -312,4 +321,15 @@ public LinkedHashMap<String, String> getMappings() {
312321
return new LinkedHashMap<>(mappings);
313322
}
314323

324+
/**
325+
* Convencience method for configuring dependencies to be checked and ignoring transitive dependencies for now.
326+
* */
327+
public void configureDependencies(
328+
Configuration plusConfiguration,
329+
Configuration minusConfiguration,
330+
Spec<ComponentIdentifier> componentFilter
331+
) {
332+
setDependencies(createFileCollectionFromNonTransitiveArtifactsView(plusConfiguration, componentFilter).minus(minusConfiguration));
333+
}
334+
315335
}

0 commit comments

Comments
 (0)