Skip to content

Commit

Permalink
[Gradle] Update shadow plugin (elastic#116826)
Browse files Browse the repository at this point in the history
- The shadow plugin has changed ownership and plugin id.
- Make some formatting of poms more reproducible

(cherry picked from commit def490e)
  • Loading branch information
breskeby committed Nov 15, 2024
1 parent ef5f439 commit 83ac08f
Show file tree
Hide file tree
Showing 22 changed files with 135 additions and 69 deletions.
7 changes: 0 additions & 7 deletions build-conventions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import org.gradle.plugins.ide.eclipse.model.SourceFolder

buildscript {
repositories {
maven {
url 'https://jitpack.io'
}
mavenCentral()
}
}
Expand Down Expand Up @@ -70,10 +67,6 @@ gradlePlugin {
}

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

mavenCentral()
gradlePluginPortal()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Project> {

Expand Down Expand Up @@ -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>) () -> 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()));
Expand All @@ -135,11 +143,26 @@ private void configurePomGeneration(Project project) {
});
}

private void addNameAndDescriptiontoPom(Project project, NamedDomainObjectSet<MavenPublication> 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<MavenPublication> 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());
}));
Expand Down
3 changes: 0 additions & 3 deletions build-tools-internal/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,6 @@ tasks.named('licenseHeaders').configure {
*****************************************************************************/

repositories {
maven {
url 'https://jitpack.io'
}
mavenCentral()
gradlePluginPortal()
}
Expand Down
3 changes: 0 additions & 3 deletions build-tools-internal/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
pluginManagement {
repositories {
maven {
url 'https://jitpack.io'
}
mavenCentral()
gradlePluginPortal()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -117,7 +117,7 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
}
version = "1.0"
group = 'org.acme'
description = 'some description'
description = 'shadowed project'
"""

when:
Expand All @@ -137,7 +137,7 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
<artifactId>hello-world</artifactId>
<version>1.0</version>
<name>hello-world</name>
<description>some description</description>
<description>shadowed project</description>
<url>unknown</url>
<scm>
<url>unknown</url>
Expand Down Expand Up @@ -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 {
Expand All @@ -206,7 +206,7 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
group = 'org.acme'
}
description = 'some description'
description = 'with shadowed dependencies'
"""

when:
Expand All @@ -226,7 +226,7 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
<artifactId>hello-world</artifactId>
<version>1.0</version>
<name>hello-world</name>
<description>some description</description>
<description>with shadowed dependencies</description>
<url>unknown</url>
<scm>
<url>unknown</url>
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -324,7 +324,7 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
<artifactId>hello-world-plugin</artifactId>
<version>1.0</version>
<name>hello-world</name>
<description>custom project description</description>
<description>shadowed es plugin</description>
<url>unknown</url>
<scm>
<url>unknown</url>
Expand Down Expand Up @@ -353,7 +353,6 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
<url>https://www.elastic.co</url>
</developer>
</developers>
<dependencies/>
</project>"""
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 0 additions & 6 deletions build-tools/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

buildscript {
repositories {
maven {
url 'https://jitpack.io'
}
mavenCentral()
}
}
Expand Down Expand Up @@ -117,9 +114,6 @@ configurations {
}

repositories {
maven {
url 'https://jitpack.io'
}
mavenCentral()
gradlePluginPortal()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private static CopySpec createBundleSpec(
copySpec.exclude("plugin-security.codebases");
});
bundleSpec.from(
(Callable<TaskProvider<Task>>) () -> project.getPluginManager().hasPlugin("com.github.johnrengelman.shadow")
(Callable<TaskProvider<Task>>) () -> project.getPluginManager().hasPlugin("com.gradleup.shadow")
? project.getTasks().named("shadowJar")
: project.getTasks().named("jar")
);
Expand Down
4 changes: 0 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ import static org.elasticsearch.gradle.util.GradleUtils.maybeConfigure

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

mavenCentral()
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/build.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
Loading

0 comments on commit 83ac08f

Please sign in to comment.