From 68337ff66ed0e7cf8141bb2557e9ae693d401b9d Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Sat, 16 Nov 2024 15:06:35 +0100 Subject: [PATCH] [Gradle] Update shadow plugin (#116826) (#116877) - The shadow plugin has changed ownership and plugin id. - Make some formatting of poms more reproducible (cherry picked from commit def490ef85fd1d6e1f2cabe4b62f5bcf187abff5) --- build-conventions/build.gradle | 7 -- .../internal/conventions/PublishPlugin.java | 43 ++++++--- build-tools-internal/build.gradle | 3 - build-tools-internal/settings.gradle | 3 - .../ElasticsearchJavadocPluginFuncTest.groovy | 2 +- .../internal/PublishPluginFuncTest.groovy | 19 ++-- .../internal/ElasticsearchJavaPlugin.java | 2 +- .../internal/ElasticsearchTestBasePlugin.java | 2 +- build-tools/build.gradle | 6 -- .../gradle/plugin/BasePluginBuildPlugin.java | 2 +- build.gradle | 4 - gradle/build.versions.toml | 2 +- gradle/verification-metadata.xml | 90 ++++++++++++++++--- .../hadoop-client-api/build.gradle | 2 +- settings.gradle | 3 - test/fixtures/hdfs-fixture/build.gradle | 2 +- .../es-opensaml-security-api/build.gradle | 2 +- .../build.gradle | 2 +- .../build.gradle | 2 +- .../lib/nimbus-jose-jwt-modified/build.gradle | 2 +- x-pack/plugin/sql/jdbc/build.gradle | 2 +- x-pack/plugin/sql/sql-cli/build.gradle | 2 +- 22 files changed, 135 insertions(+), 69 deletions(-) diff --git a/build-conventions/build.gradle b/build-conventions/build.gradle index d8c211c0f02f9..b0eda5a34065a 100644 --- a/build-conventions/build.gradle +++ b/build-conventions/build.gradle @@ -12,9 +12,6 @@ import org.gradle.plugins.ide.eclipse.model.SourceFolder buildscript { repositories { - maven { - url 'https://jitpack.io' - } mavenCentral() } } @@ -70,10 +67,6 @@ gradlePlugin { } repositories { - maven { - url 'https://jitpack.io' - } - mavenCentral() gradlePluginPortal() } diff --git a/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/PublishPlugin.java b/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/PublishPlugin.java index cd13743ee0746..d19a1d492d9ed 100644 --- a/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/PublishPlugin.java +++ b/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/PublishPlugin.java @@ -9,15 +9,19 @@ package org.elasticsearch.gradle.internal.conventions; -import org.elasticsearch.gradle.internal.conventions.precommit.PomValidationPrecommitPlugin; +import groovy.util.Node; + import com.github.jengelman.gradle.plugins.shadow.ShadowExtension; import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin; -import groovy.util.Node; -import org.elasticsearch.gradle.internal.conventions.util.Util; + import org.elasticsearch.gradle.internal.conventions.info.GitInfo; +import org.elasticsearch.gradle.internal.conventions.precommit.PomValidationPrecommitPlugin; +import org.elasticsearch.gradle.internal.conventions.util.Util; +import org.gradle.api.Action; import org.gradle.api.NamedDomainObjectSet; import org.gradle.api.Plugin; import org.gradle.api.Project; +import org.gradle.api.Task; import org.gradle.api.XmlProvider; import org.gradle.api.file.ProjectLayout; import org.gradle.api.plugins.BasePlugin; @@ -35,11 +39,12 @@ import org.gradle.api.tasks.bundling.Jar; import org.gradle.initialization.layout.BuildLayout; import org.gradle.language.base.plugins.LifecycleBasePlugin; +import org.w3c.dom.Element; -import javax.inject.Inject; import java.io.File; import java.util.Map; import java.util.concurrent.Callable; +import javax.inject.Inject; public class PublishPlugin implements Plugin { @@ -113,19 +118,22 @@ private void configurePomGeneration(Project project) { var archivesBaseName = providerFactory.provider(() -> getArchivesBaseName(extensions)); var projectVersion = providerFactory.provider(() -> project.getVersion()); var generateMavenPoms = project.getTasks().withType(GenerateMavenPom.class); - generateMavenPoms.configureEach( - pomTask -> pomTask.setDestination( + generateMavenPoms.configureEach(pomTask -> { + pomTask.setDestination( (Callable) () -> String.format( "%s/distributions/%s-%s.pom", projectLayout.getBuildDirectory().get().getAsFile().getPath(), archivesBaseName.get(), projectVersion.get() ) - ) - ); + ); + pomTask.doFirst(t -> pomTask.getPom().withXml(xml -> formatDependencies(xml))); + }); + var publishing = extensions.getByType(PublishingExtension.class); final var mavenPublications = publishing.getPublications().withType(MavenPublication.class); - addNameAndDescriptiontoPom(project, mavenPublications); + + addNameAndDescriptionToPom(project, mavenPublications); mavenPublications.configureEach(publication -> { // Add git origin info to generated POM files for internal builds publication.getPom().withXml(xml -> addScmInfo(xml, gitInfo.get())); @@ -135,11 +143,26 @@ private void configurePomGeneration(Project project) { }); } - private void addNameAndDescriptiontoPom(Project project, NamedDomainObjectSet mavenPublications) { + /** + * just ensure we put dependencies to the end. more a cosmetic thing than anything else + * */ + private void formatDependencies(XmlProvider xml) { + Element rootElement = xml.asElement(); + var dependencies = rootElement.getElementsByTagName("dependencies"); + if (dependencies.getLength() == 1 && dependencies.item(0) != null) { + org.w3c.dom.Node item = dependencies.item(0); + rootElement.removeChild(item); + rootElement.appendChild(item); + } + } + + private void addNameAndDescriptionToPom(Project project, NamedDomainObjectSet mavenPublications) { var name = project.getName(); var description = providerFactory.provider(() -> project.getDescription() != null ? project.getDescription() : ""); mavenPublications.configureEach(p -> p.getPom().withXml(xml -> { var root = xml.asNode(); + // Node versionNode = root.get("version"); + // versionNode.plus(1, "name", name); root.appendNode("name", name); root.appendNode("description", description.get()); })); diff --git a/build-tools-internal/build.gradle b/build-tools-internal/build.gradle index 38d3c0cd326f9..a340a088eed50 100644 --- a/build-tools-internal/build.gradle +++ b/build-tools-internal/build.gradle @@ -258,9 +258,6 @@ tasks.named('licenseHeaders').configure { *****************************************************************************/ repositories { - maven { - url 'https://jitpack.io' - } mavenCentral() gradlePluginPortal() } diff --git a/build-tools-internal/settings.gradle b/build-tools-internal/settings.gradle index 1b4fb1215a59d..8c88d36046768 100644 --- a/build-tools-internal/settings.gradle +++ b/build-tools-internal/settings.gradle @@ -1,8 +1,5 @@ pluginManagement { repositories { - maven { - url 'https://jitpack.io' - } mavenCentral() gradlePluginPortal() } diff --git a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/ElasticsearchJavadocPluginFuncTest.groovy b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/ElasticsearchJavadocPluginFuncTest.groovy index b853fdef6a13f..34fa73ce502ac 100644 --- a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/ElasticsearchJavadocPluginFuncTest.groovy +++ b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/ElasticsearchJavadocPluginFuncTest.groovy @@ -73,7 +73,7 @@ class ElasticsearchJavadocPluginFuncTest extends AbstractGradleFuncTest { buildFile << """ plugins { id 'elasticsearch.java-doc' - id 'com.github.johnrengelman.shadow' version '7.1.2' + id 'com.gradleup.shadow' id 'java' } group = 'org.acme.depending' diff --git a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy index 99d451116dbe7..851994c362b14 100644 --- a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy +++ b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy @@ -96,7 +96,7 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { plugins { id 'elasticsearch.java' id 'elasticsearch.publish' - id 'com.github.johnrengelman.shadow' + id 'com.gradleup.shadow' } repositories { @@ -117,7 +117,7 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { } version = "1.0" group = 'org.acme' - description = 'some description' + description = 'shadowed project' """ when: @@ -137,7 +137,7 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { hello-world 1.0 hello-world - some description + shadowed project unknown unknown @@ -186,7 +186,7 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { plugins { id 'elasticsearch.java' id 'elasticsearch.publish' - id 'com.github.johnrengelman.shadow' + id 'com.gradleup.shadow' } dependencies { @@ -206,7 +206,7 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { group = 'org.acme' } - description = 'some description' + description = 'with shadowed dependencies' """ when: @@ -226,7 +226,7 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { hello-world 1.0 hello-world - some description + with shadowed dependencies unknown unknown @@ -277,13 +277,13 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { plugins { id 'elasticsearch.internal-es-plugin' id 'elasticsearch.publish' - id 'com.github.johnrengelman.shadow' + id 'com.gradleup.shadow' } esplugin { name = 'hello-world-plugin' classname 'org.acme.HelloWorldPlugin' - description = "custom project description" + description = "shadowed es plugin" } publishing { @@ -324,7 +324,7 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { hello-world-plugin 1.0 hello-world - custom project description + shadowed es plugin unknown unknown @@ -353,7 +353,6 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { https://www.elastic.co - """ ) } diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavaPlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavaPlugin.java index d064c70c72819..0b7ed6a58a9f0 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavaPlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavaPlugin.java @@ -82,7 +82,7 @@ public void execute(Task task) { } }); }); - project.getPluginManager().withPlugin("com.github.johnrengelman.shadow", p -> { + project.getPluginManager().withPlugin("com.gradleup.shadow", p -> { project.getTasks().withType(ShadowJar.class).configureEach(shadowJar -> { /* * Replace the default "-all" classifier with null diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchTestBasePlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchTestBasePlugin.java index 7a831fbcc1464..72c2c4980a56b 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchTestBasePlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchTestBasePlugin.java @@ -193,7 +193,7 @@ public void execute(Task t) { * If this project builds a shadow JAR than any unit tests should test against that artifact instead of * compiled class output and dependency jars. This better emulates the runtime environment of consumers. */ - project.getPluginManager().withPlugin("com.github.johnrengelman.shadow", p -> { + project.getPluginManager().withPlugin("com.gradleup.shadow", p -> { if (test.getName().equals(JavaPlugin.TEST_TASK_NAME)) { // Remove output class files and any other dependencies from the test classpath, since the shadow JAR includes these SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class); diff --git a/build-tools/build.gradle b/build-tools/build.gradle index 7fd01f0c3d4f7..e457999fedfee 100644 --- a/build-tools/build.gradle +++ b/build-tools/build.gradle @@ -9,9 +9,6 @@ buildscript { repositories { - maven { - url 'https://jitpack.io' - } mavenCentral() } } @@ -117,9 +114,6 @@ configurations { } repositories { - maven { - url 'https://jitpack.io' - } mavenCentral() gradlePluginPortal() } diff --git a/build-tools/src/main/java/org/elasticsearch/gradle/plugin/BasePluginBuildPlugin.java b/build-tools/src/main/java/org/elasticsearch/gradle/plugin/BasePluginBuildPlugin.java index e3adfe8d28148..b3a792b418384 100644 --- a/build-tools/src/main/java/org/elasticsearch/gradle/plugin/BasePluginBuildPlugin.java +++ b/build-tools/src/main/java/org/elasticsearch/gradle/plugin/BasePluginBuildPlugin.java @@ -167,7 +167,7 @@ private static CopySpec createBundleSpec( copySpec.exclude("plugin-security.codebases"); }); bundleSpec.from( - (Callable>) () -> project.getPluginManager().hasPlugin("com.github.johnrengelman.shadow") + (Callable>) () -> project.getPluginManager().hasPlugin("com.gradleup.shadow") ? project.getTasks().named("shadowJar") : project.getTasks().named("jar") ); diff --git a/build.gradle b/build.gradle index 99ad6c814b9d1..a9493c8154d87 100644 --- a/build.gradle +++ b/build.gradle @@ -29,10 +29,6 @@ import static org.elasticsearch.gradle.util.GradleUtils.maybeConfigure buildscript { repositories { - maven { - url 'https://jitpack.io' - } - mavenCentral() } } diff --git a/gradle/build.versions.toml b/gradle/build.versions.toml index d11c4b7fd9c91..e3148c6f3ef2e 100644 --- a/gradle/build.versions.toml +++ b/gradle/build.versions.toml @@ -39,7 +39,7 @@ maven-model = "org.apache.maven:maven-model:3.6.2" mockito-core = "org.mockito:mockito-core:1.9.5" nebula-info = "com.netflix.nebula:gradle-info-plugin:11.3.3" reflections = "org.reflections:reflections:0.9.12" -shadow-plugin = "com.github.breskeby:shadow:3b035f2" +shadow-plugin = "com.gradleup.shadow:shadow-gradle-plugin:8.3.5" snakeyaml = { group = "org.yaml", name = "snakeyaml", version = { strictly = "2.0" } } spock-core = { group = "org.spockframework", name="spock-core", version.ref="spock" } spock-junit4 = { group = "org.spockframework", name="spock-junit4", version.ref="spock" } diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 22827e5f4bd33..bc813d9688060 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -409,21 +409,16 @@ + + + + + - - - - - - - - - - @@ -794,6 +789,11 @@ + + + + + @@ -1231,6 +1231,11 @@ + + + + + @@ -1917,6 +1922,11 @@ + + + + + @@ -1932,6 +1942,11 @@ + + + + + @@ -2805,6 +2820,11 @@ + + + + + @@ -2825,6 +2845,11 @@ + + + + + @@ -2960,6 +2985,16 @@ + + + + + + + + + + @@ -3015,6 +3050,11 @@ + + + + + @@ -3388,6 +3428,16 @@ + + + + + + + + + + @@ -4148,6 +4198,11 @@ + + + + + @@ -4193,6 +4248,11 @@ + + + + + @@ -4233,6 +4293,11 @@ + + + + + @@ -4413,6 +4478,11 @@ + + + + + diff --git a/plugins/repository-hdfs/hadoop-client-api/build.gradle b/plugins/repository-hdfs/hadoop-client-api/build.gradle index 4ac6f79530fcb..24e4213780fe2 100644 --- a/plugins/repository-hdfs/hadoop-client-api/build.gradle +++ b/plugins/repository-hdfs/hadoop-client-api/build.gradle @@ -1,5 +1,5 @@ apply plugin: 'elasticsearch.build' -apply plugin: 'com.github.johnrengelman.shadow' +apply plugin: 'com.gradleup.shadow' dependencies { implementation "org.apache.hadoop:hadoop-client-api:${project.parent.versions.hadoop}" diff --git a/settings.gradle b/settings.gradle index b696d9635d974..e8d0c8ac95ed5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,9 +4,6 @@ import org.elasticsearch.gradle.internal.toolchain.AdoptiumJdkToolchainResolver pluginManagement { repositories { - maven { - url 'https://jitpack.io' - } mavenCentral() gradlePluginPortal() } diff --git a/test/fixtures/hdfs-fixture/build.gradle b/test/fixtures/hdfs-fixture/build.gradle index 8911bdf286a0f..9dc0263f49aee 100644 --- a/test/fixtures/hdfs-fixture/build.gradle +++ b/test/fixtures/hdfs-fixture/build.gradle @@ -8,7 +8,7 @@ */ apply plugin: 'elasticsearch.java' -apply plugin: 'com.github.johnrengelman.shadow' +apply plugin: 'com.gradleup.shadow' import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar diff --git a/x-pack/libs/es-opensaml-security-api/build.gradle b/x-pack/libs/es-opensaml-security-api/build.gradle index b36d0bfa7b37d..3b4434ec5d9e5 100644 --- a/x-pack/libs/es-opensaml-security-api/build.gradle +++ b/x-pack/libs/es-opensaml-security-api/build.gradle @@ -7,7 +7,7 @@ apply plugin: 'elasticsearch.build' apply plugin: 'elasticsearch.publish' -apply plugin: 'com.github.johnrengelman.shadow' +apply plugin: 'com.gradleup.shadow' dependencies { implementation "org.opensaml:opensaml-security-api:${versions.opensaml}" diff --git a/x-pack/plugin/security/lib/nimbus-jose-jwt-modified-part1/build.gradle b/x-pack/plugin/security/lib/nimbus-jose-jwt-modified-part1/build.gradle index f751fcd0a655d..f53ff7027f126 100644 --- a/x-pack/plugin/security/lib/nimbus-jose-jwt-modified-part1/build.gradle +++ b/x-pack/plugin/security/lib/nimbus-jose-jwt-modified-part1/build.gradle @@ -6,7 +6,7 @@ */ apply plugin: 'elasticsearch.build' -apply plugin: 'com.github.johnrengelman.shadow' +apply plugin: 'com.gradleup.shadow' // See the build.gradle file in the parent directory for an explanation of this unusual build diff --git a/x-pack/plugin/security/lib/nimbus-jose-jwt-modified-part2/build.gradle b/x-pack/plugin/security/lib/nimbus-jose-jwt-modified-part2/build.gradle index c4c0f2ebd2fe1..d24299a3847da 100644 --- a/x-pack/plugin/security/lib/nimbus-jose-jwt-modified-part2/build.gradle +++ b/x-pack/plugin/security/lib/nimbus-jose-jwt-modified-part2/build.gradle @@ -6,7 +6,7 @@ */ apply plugin: 'elasticsearch.build' -apply plugin: 'com.github.johnrengelman.shadow' +apply plugin: 'com.gradleup.shadow' // See the build.gradle file in the parent directory for an explanation of this unusual build diff --git a/x-pack/plugin/security/lib/nimbus-jose-jwt-modified/build.gradle b/x-pack/plugin/security/lib/nimbus-jose-jwt-modified/build.gradle index 580ca45055219..4418bd32e64cf 100644 --- a/x-pack/plugin/security/lib/nimbus-jose-jwt-modified/build.gradle +++ b/x-pack/plugin/security/lib/nimbus-jose-jwt-modified/build.gradle @@ -6,7 +6,7 @@ */ apply plugin: 'elasticsearch.build' -apply plugin: 'com.github.johnrengelman.shadow' +apply plugin: 'com.gradleup.shadow' // See the build.gradle file in the parent directory for an explanation of this unusual build diff --git a/x-pack/plugin/sql/jdbc/build.gradle b/x-pack/plugin/sql/jdbc/build.gradle index 138f3e63af462..d1b179f09e403 100644 --- a/x-pack/plugin/sql/jdbc/build.gradle +++ b/x-pack/plugin/sql/jdbc/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'elasticsearch.build' apply plugin: 'elasticsearch.publish' -apply plugin: 'com.github.johnrengelman.shadow' +apply plugin: 'com.gradleup.shadow' description = 'JDBC driver for Elasticsearch' diff --git a/x-pack/plugin/sql/sql-cli/build.gradle b/x-pack/plugin/sql/sql-cli/build.gradle index 1d3a63ec13c98..109f20fe78861 100644 --- a/x-pack/plugin/sql/sql-cli/build.gradle +++ b/x-pack/plugin/sql/sql-cli/build.gradle @@ -8,7 +8,7 @@ import org.elasticsearch.gradle.internal.info.BuildParams */ apply plugin: 'elasticsearch.build' -apply plugin: 'com.github.johnrengelman.shadow' +apply plugin: 'com.gradleup.shadow' /* We don't use the 'application' plugin because it builds a zip and tgz which * we don't want. */