From 4da6b40193024228fa5a60e21c2abc7fd993f98b Mon Sep 17 00:00:00 2001 From: Gerd Aschemann Date: Mon, 29 Jun 2026 22:46:28 +0200 Subject: [PATCH] [#819] Fix DRP exclusion loss on classifier dups Under Maven 4, ShadeMojo.updateExcludesInDeps() walks a single conflict-resolved collect graph. The resolver prunes the duplicate transitive node ("omitted for duplicate") under one of two classifier-distinct variants of the same artifact, so the generated dependency-reduced-pom keeps the on only one variant. Collect that graph with verbose conflict resolution (ConflictResolver.CONFIG_PROP_VERBOSE = STANDARD) so the omitted-duplicate node is retained as a marker; the existing walk then re-attaches the exclusion to both variants. No behaviour change on Maven 3.9.16. Covered by the existing dep-reduced-pom-exclusions and MSHADE-467_parallel-dependency-reduced-pom ITs. Closes #819 Co-Authored-By: Claude Opus 4.8 (1M context) --- .../apache/maven/plugins/shade/mojo/ShadeMojo.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java b/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java index 4ff74fa3..412554c2 100644 --- a/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java +++ b/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java @@ -71,6 +71,7 @@ import org.apache.maven.project.ProjectBuildingResult; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.WriterFactory; +import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.collection.CollectRequest; import org.eclipse.aether.collection.CollectResult; @@ -78,6 +79,7 @@ import org.eclipse.aether.graph.DependencyNode; import org.eclipse.aether.resolution.ArtifactRequest; import org.eclipse.aether.resolution.ArtifactResolutionException; +import org.eclipse.aether.util.graph.transformer.ConflictResolver; import static org.apache.maven.plugins.shade.resource.UseDependencyReducedPom.createPomReplaceTransformers; @@ -1299,7 +1301,15 @@ public boolean updateExcludesInDeps( d, session.getRepositorySession().getArtifactTypeRegistry())) .collect(Collectors.toList())); } - CollectResult result = repositorySystem.collectDependencies(session.getRepositorySession(), collectRequest); + // #819: collect with verbose conflict resolution so that dependencies omitted as conflict + // losers (e.g. a transitive dependency shared by two classifier-distinct variants of the same + // artifact) are retained in the graph as markers. Without this, conflict resolution under Maven 4 + // prunes the duplicate node from all but one variant, and the exclusion is only applied to that + // single variant in the dependency-reduced-pom. + DefaultRepositorySystemSession verboseSession = + new DefaultRepositorySystemSession(session.getRepositorySession()); + verboseSession.setConfigProperty(ConflictResolver.CONFIG_PROP_VERBOSE, ConflictResolver.Verbosity.STANDARD); + CollectResult result = repositorySystem.collectDependencies(verboseSession, collectRequest); boolean modified = false; if (result.getRoot() != null) { for (DependencyNode n2 : result.getRoot().getChildren()) {