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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to