You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "efegokdemir (via GitHub)" <gi...@apache.org> on 2026/10/07 21:33:40 UTC

[PR] [#864] Fix Maven 4 shaded consumer POM [maven-shade-plugin]

efegokdemir opened a new pull request, #865:
URL: https://github.com/apache/maven-shade-plugin/pull/865

   Fixes #864
   
   ## What
   
   Keep Maven 4's installed consumer POM dependency-reduced when the Shade plugin removes dependencies from the shaded artifact.
   
   ## Why
   
   Maven 4 attaches a lazy consumer POM before the Shade goal runs. Updating `MavenProject.file` changes the build POM, while the consumer POM continues to be generated from the original project POM, so downstream users resolve dependencies already included in the shaded JAR.
   
   ## How
   
   After writing the dependency-reduced POM, the plugin materializes Maven 4's existing `pom:consumer` artifact and replaces its generated file with the reduced POM. It does not add a duplicate artifact. The Maven 3 path remains unchanged.
   
   ## Testing
   
   - Added an install integration test adapted from the reproducer linked in #864. It checks the installed consumer POM and build POM, and verifies that the original project POM remains unchanged.
   - Maven 3.10.0 / JDK 17: `mvn -B -Prun-its -Dinvoker.test=dep-reduced-pom-864 verify` — passed (72 unit tests and the targeted IT).
   - Maven 4.0.0-rc-7 / JDK 17: `/tmp/maven-4-rc7/bin/mvn -B -Prun-its -Dinvoker.test=dep-reduced-pom-864 verify` — passed (72 unit tests and the targeted IT).
   - Fail-before evidence: the new IT failed on the unmodified implementation because the installed consumer POM still declared all four shaded dependencies; it passes after this change.
   - Checkstyle and Spotless ran as part of both verification commands; `git diff --check` passed.
   
   ## Compatibility
   
   Maven 3 behavior is unchanged. Maven 4 keeps the dependency-reduced POM as its build POM and now uses it for the consumer POM as well.
   
   AI assistance: OpenAI Codex (GPT-6) assisted with investigation, implementation, and test drafting. The commit includes the ASF `Generated-by` provenance trailer.
   
   ## Checklist
   
   - [x] I hereby declare this contribution to be licensed under the Apache License Version 2.0, January 2004
   - [ ] I hereby declare that I have filed an Apache Individual Contributor License Agreement
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#864] Fix Maven 4 shaded consumer POM [maven-shade-plugin]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #865:
URL: https://github.com/apache/maven-shade-plugin/pull/865#discussion_r4366933041


##########
src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java:
##########
@@ -1257,6 +1258,27 @@ private void rewriteDependencyReducedPomIfWeHaveReduction(
             }
 
             project.setFile(dependencyReducedPomLocation);
+            updateMaven4ConsumerPom();
+        }
+    }
+
+    private void updateMaven4ConsumerPom() throws IOException {
+        if (!session.getSystemProperties().getProperty("maven.version", "").startsWith("4.")) {
+            return;
+        }
+
+        // Maven 4 attaches its consumer POM before this mojo runs, so project.setFile() only updates the build POM.
+        // Replace the already materialized consumer POM with the dependency-reduced POM as well.
+        for (Artifact artifact : project.getAttachedArtifacts()) {
+            if ("pom".equals(artifact.getType()) && "consumer".equals(artifact.getClassifier())) {
+                File consumerPom = artifact.getFile();
+                if (consumerPom != null) {
+                    Files.copy(
+                            dependencyReducedPomLocation.toPath(),
+                            consumerPom.toPath(),
+                            StandardCopyOption.REPLACE_EXISTING);

Review Comment:
   Copying the reduced build POM wholesale discards Maven 4's consumer-POM transformations because it is serialized from `project.getOriginalModel()`. For example, a parent version specified as `${revision}` and supplied via `-Drevision=1.2.3` is published unresolved, preventing downstream builds from resolving the parent. Apply dependency reduction while preserving the transformed consumer model, or regenerate the consumer POM from the reduced model, and add a Maven 4 regression test with a CI-friendly parent version.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org