Skip to content

Commit

Permalink
Update Gradle wrapper to 8.8 (#108021)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
breskeby authored Jun 4, 2024
1 parent d543d91 commit 8ac3e3d
Show file tree
Hide file tree
Showing 29 changed files with 351 additions and 230 deletions.
14 changes: 14 additions & 0 deletions build-conventions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@

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


buildscript {
repositories {
maven {
url 'https://jitpack.io'
}
mavenCentral()
}
}

plugins {
id 'java-gradle-plugin'
id 'java-test-fixtures'
Expand Down Expand Up @@ -59,6 +69,10 @@ gradlePlugin {
}

repositories {
maven {
url 'https://jitpack.io'
}

mavenCentral()
gradlePluginPortal()
}
Expand Down
3 changes: 3 additions & 0 deletions build-tools-internal/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ tasks.named('licenseHeaders').configure {
*****************************************************************************/

repositories {
maven {
url 'https://jitpack.io'
}
mavenCentral()
gradlePluginPortal()
}
Expand Down
4 changes: 2 additions & 2 deletions build-tools-internal/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=194717442575a6f96e1c1befa2c30e9a4fc90f701d7aee33eb879b79e7ff05c0
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
distributionSha256Sum=f8b4f4772d302c8ff580bc40d0f56e715de69b163546944f787c87abf209c961
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
12 changes: 10 additions & 2 deletions build-tools-internal/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
pluginManagement {
includeBuild "../build-conventions"
repositories {
maven {
url 'https://jitpack.io'
}
mavenCentral()
gradlePluginPortal()
}

includeBuild "../build-conventions"
includeBuild "../build-tools"
}

Expand All @@ -9,4 +17,4 @@ dependencyResolutionManagement {
from(files("../gradle/build.versions.toml"))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ private void configureGeneralTaskDefaults(Project project) {
project.getTasks().withType(AbstractCopyTask.class).configureEach(t -> {
t.dependsOn(project.getTasks().withType(EmptyDirTask.class));
t.setIncludeEmptyDirs(true);
t.setDirMode(0755);
t.setFileMode(0644);
t.dirPermissions(permissions -> permissions.unix(0755));
t.filePermissions(permissions -> permissions.unix(0644));
});

// common config across all archives
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private void visitSymbolicLink(final FileCopyDetailsInternal details) {
visitedSymbolicLinks.add(details.getFile());
final TarArchiveEntry entry = new TarArchiveEntry(details.getRelativePath().getPathString(), TarConstants.LF_SYMLINK);
entry.setModTime(getModTime(details));
entry.setMode(UnixStat.LINK_FLAG | details.getMode());
entry.setMode(UnixStat.LINK_FLAG | details.getPermissions().toUnixNumeric());
try {
entry.setLinkName(Files.readSymbolicLink(details.getFile().toPath()).toString());
tar.putArchiveEntry(entry);
Expand All @@ -158,7 +158,7 @@ private void visitSymbolicLink(final FileCopyDetailsInternal details) {
private void visitDirectory(final FileCopyDetailsInternal details) {
final TarArchiveEntry entry = new TarArchiveEntry(details.getRelativePath().getPathString() + "/");
entry.setModTime(getModTime(details));
entry.setMode(UnixStat.DIR_FLAG | details.getMode());
entry.setMode(UnixStat.DIR_FLAG | details.getPermissions().toUnixNumeric());
try {
tar.putArchiveEntry(entry);
tar.closeArchiveEntry();
Expand All @@ -170,7 +170,7 @@ private void visitDirectory(final FileCopyDetailsInternal details) {
private void visitFile(final FileCopyDetailsInternal details) {
final TarArchiveEntry entry = new TarArchiveEntry(details.getRelativePath().getPathString());
entry.setModTime(getModTime(details));
entry.setMode(UnixStat.FILE_FLAG | details.getMode());
entry.setMode(UnixStat.FILE_FLAG | details.getPermissions().toUnixNumeric());
entry.setSize(details.getSize());
try {
tar.putArchiveEntry(entry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private List<JavaHome> getAvailableJavaVersions() {
private Stream<InstallationLocation> getAvailableJavaInstallationLocationSteam() {
return Stream.concat(
javaInstallationRegistry.toolchains().stream().map(metadata -> metadata.location),
Stream.of(new InstallationLocation(Jvm.current().getJavaHome(), "Current JVM"))
Stream.of(InstallationLocation.userDefined(Jvm.current().getJavaHome(), "Current JVM"))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,23 @@
import org.elasticsearch.gradle.internal.conventions.precommit.PrecommitPlugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.artifacts.component.ComponentIdentifier;
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.specs.Spec;
import org.gradle.api.tasks.TaskProvider;

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

@Override
public TaskProvider<? extends Task> createTask(Project project) {
project.getPlugins().apply(CompileOnlyResolvePlugin.class);
TaskProvider<DependencyLicensesTask> dependencyLicenses = project.getTasks()
.register("dependencyLicenses", DependencyLicensesTask.class);

// only require dependency licenses for non-elasticsearch deps
dependencyLicenses.configure(t -> {
Configuration runtimeClasspath = project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);
Configuration compileOnly = project.getConfigurations()
.getByName(CompileOnlyResolvePlugin.RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME);
t.setDependencies(
runtimeClasspath.fileCollection(
dependency -> dependency instanceof ProjectDependency == false
&& dependency.getGroup().startsWith("org.elasticsearch") == false
).minus(compileOnly)
);
var dependencyLicenses = project.getTasks().register("dependencyLicenses", DependencyLicensesTask.class, t -> {
var runtimeClasspath = project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);
var compileOnly = project.getConfigurations().getByName(CompileOnlyResolvePlugin.RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME);
t.configureDependencies(runtimeClasspath, compileOnly, COMPONENT_FILTER);
});
return dependencyLicenses;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.InvalidUserDataException;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.component.ComponentIdentifier;
import org.gradle.api.file.Directory;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.ProjectLayout;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.specs.Spec;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputDirectory;
import org.gradle.api.tasks.InputFiles;
Expand All @@ -41,6 +45,8 @@

import javax.inject.Inject;

import static org.elasticsearch.gradle.internal.util.DependenciesUtils.createFileCollectionFromNonTransitiveArtifactsView;

/**
* A task to check licenses for dependencies.
* <p>
Expand Down Expand Up @@ -83,7 +89,7 @@
* for the dependency. This artifact will be redistributed by us with the release to
* comply with the license terms.
*/
public class DependencyLicensesTask extends DefaultTask {
public abstract class DependencyLicensesTask extends DefaultTask {

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

Expand Down Expand Up @@ -181,6 +187,10 @@ public void ignoreFile(String file) {
ignoreFiles.add(file);
}

@Input
@Optional
public abstract Property<Spec<ComponentIdentifier>> getComponentFilter();

@TaskAction
public void checkDependencies() {
if (dependencies == null) {
Expand Down Expand Up @@ -295,7 +305,6 @@ private String getFileName(String name, Map<String, ?> counters, String type) {
// try the other suffix...TODO: get rid of this, just support ending in .txt
return fileName + ".txt";
}

return fileName;
}

Expand All @@ -310,4 +319,15 @@ public LinkedHashMap<String, String> getMappings() {
return new LinkedHashMap<>(mappings);
}

/**
* Convencience method for configuring dependencies to be checked and ignoring transitive dependencies for now.
* */
public void configureDependencies(
Configuration plusConfiguration,
Configuration minusConfiguration,
Spec<ComponentIdentifier> componentFilter
) {
setDependencies(createFileCollectionFromNonTransitiveArtifactsView(plusConfiguration, componentFilter).minus(minusConfiguration));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
import org.gradle.api.tasks.TaskProvider;

import java.io.File;
import java.nio.file.Path;

import static org.elasticsearch.gradle.internal.util.DependenciesUtils.createFileCollectionFromNonTransitiveArtifactsView;

public class ThirdPartyAuditPrecommitPlugin extends PrecommitPlugin {

public static final String JDK_JAR_HELL_CONFIG_NAME = "jdkJarHell";
Expand Down Expand Up @@ -54,12 +57,14 @@ public TaskProvider<? extends Task> createTask(Project project) {
Configuration compileOnly = project.getConfigurations()
.getByName(CompileOnlyResolvePlugin.RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME);
t.setClasspath(runtimeConfiguration.plus(compileOnly));
t.getJarsToScan().from(runtimeConfiguration.fileCollection(dep -> {
// These are SelfResolvingDependency, and some of them backed by file collections, like the Gradle API files,
// or dependencies added as `files(...)`, we can't be sure if those are third party or not.
// err on the side of scanning these to make sure we don't miss anything
return dep.getGroup() != null && dep.getGroup().startsWith("org.elasticsearch") == false;
}));
t.getJarsToScan()
.from(
createFileCollectionFromNonTransitiveArtifactsView(
runtimeConfiguration,
identifier -> identifier instanceof ModuleComponentIdentifier
&& ((ModuleComponentIdentifier) identifier).getGroup().startsWith("org.elasticsearch") == false
)
);
t.dependsOn(resourcesTask);
if (BuildParams.getIsRuntimeJavaHomeSet()) {
t.getJavaHome().set(project.provider(BuildParams::getRuntimeJavaHome).map(File::getPath));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.gradle.internal.util;

import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ResolvableDependencies;
import org.gradle.api.artifacts.component.ComponentIdentifier;
import org.gradle.api.artifacts.result.ResolvedComponentResult;
import org.gradle.api.artifacts.result.ResolvedDependencyResult;
import org.gradle.api.file.FileCollection;
import org.gradle.api.specs.AndSpec;
import org.gradle.api.specs.Spec;

import java.util.Set;
import java.util.stream.Collectors;

public class DependenciesUtils {

public static FileCollection createFileCollectionFromNonTransitiveArtifactsView(
Configuration configuration,
Spec<ComponentIdentifier> componentFilter
) {
ResolvableDependencies incoming = configuration.getIncoming();
return incoming.artifactView(viewConfiguration -> {
Set<ComponentIdentifier> firstLevelDependencyComponents = incoming.getResolutionResult()
.getRootComponent()
.map(
rootComponent -> rootComponent.getDependencies()
.stream()
.filter(dependency -> dependency instanceof ResolvedDependencyResult)
.map(dependency -> (ResolvedDependencyResult) dependency)
.filter(dependency -> dependency.getSelected() instanceof ResolvedComponentResult)
.map(dependency -> dependency.getSelected().getId())
.collect(Collectors.toSet())
)
.get();
viewConfiguration.componentFilter(
new AndSpec<>(identifier -> firstLevelDependencyComponents.contains(identifier), componentFilter)
);
}).getFiles();
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.7
8.8
Loading

0 comments on commit 8ac3e3d

Please sign in to comment.