From edfe896ba2c27e45c43542d3cbf64b66ed6ef6df Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Tue, 28 Nov 2023 13:34:49 -0500 Subject: [PATCH] Fix Shadow JAR dependency publication Signed-off-by: Andriy Redko --- CHANGELOG.md | 1 + .../org/opensearch/gradle/PublishPlugin.java | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e42f44344668c..db1a94a134837 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -168,6 +168,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Delegating CachingWeightWrapper#count to internal weight object ([#10543](https://github.com/opensearch-project/OpenSearch/pull/10543)) - Fix per request latency last phase not tracked ([#10934](https://github.com/opensearch-project/OpenSearch/pull/10934)) - Fix for stuck update action in a bulk with `retry_on_conflict` property ([#11152](https://github.com/opensearch-project/OpenSearch/issues/11152)) +- Fix Shadow JAR dependency publication ([#11369](https://github.com/opensearch-project/OpenSearch/issues/11369)) ### Security diff --git a/buildSrc/src/main/java/org/opensearch/gradle/PublishPlugin.java b/buildSrc/src/main/java/org/opensearch/gradle/PublishPlugin.java index 97e923c366598..31ae41eab7972 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/PublishPlugin.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/PublishPlugin.java @@ -32,7 +32,6 @@ package org.opensearch.gradle; -import com.github.jengelman.gradle.plugins.shadow.ShadowBasePlugin; import com.github.jengelman.gradle.plugins.shadow.ShadowExtension; import groovy.util.Node; import groovy.util.NodeList; @@ -44,7 +43,9 @@ import org.gradle.api.Project; import org.gradle.api.Task; import org.gradle.api.XmlProvider; +import org.gradle.api.artifacts.ConfigurationContainer; import org.gradle.api.artifacts.ProjectDependency; +import org.gradle.api.artifacts.SelfResolvingDependency; import org.gradle.api.plugins.BasePlugin; import org.gradle.api.plugins.BasePluginExtension; import org.gradle.api.plugins.JavaPlugin; @@ -116,7 +117,8 @@ public String call() throws Exception { root.appendNode("description", project.getDescription()); } Node dependenciesNode = (Node) ((NodeList) root.get("dependencies")).get(0); - project.getConfigurations().getByName(ShadowBasePlugin.CONFIGURATION_NAME).getAllDependencies().all(dependency -> { + final ConfigurationContainer configurations = project.getConfigurations(); + configurations.getByName(JavaPlugin.API_CONFIGURATION_NAME).getDependencies().all(dependency -> { if (dependency instanceof ProjectDependency) { Node dependencyNode = dependenciesNode.appendNode("dependency"); dependencyNode.appendNode("groupId", dependency.getGroup()); @@ -125,6 +127,17 @@ public String call() throws Exception { dependencyNode.appendNode("artifactId", artifactId); dependencyNode.appendNode("version", dependency.getVersion()); dependencyNode.appendNode("scope", "compile"); + } else if (!(dependency instanceof SelfResolvingDependency)) { + Node dependencyNode = dependenciesNode.appendNode("dependency"); + dependencyNode.appendNode("groupId", dependency.getGroup()); + dependencyNode.appendNode("artifactId", dependency.getName()); + dependencyNode.appendNode("version", dependency.getVersion()); + dependencyNode.appendNode("scope", "compile"); + + final Node exclusions = dependencyNode.appendNode("exclusions"); + final Node exclusion = exclusions.appendNode("exclusion"); + exclusion.appendNode("groupId", "*"); + exclusion.appendNode("artifactId", "*"); } }); });