This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/master by this push:
     new 93b85b05ca Fix ReactorReader to prefer consumer POMs over build POMs 
(#11107)
93b85b05ca is described below

commit 93b85b05cab932575e5240b8e3a9a42519104779
Author: Guillaume Nodet <[email protected]>
AuthorDate: Wed Sep 17 12:48:06 2025 +0200

    Fix ReactorReader to prefer consumer POMs over build POMs (#11107)
    
    * ReactorReader: prefer consumer POM from project-local repo when resolving 
POMs
    
    When only part of a reactor is built, ReactorReader mirrors artifacts into 
a project-local repo. If a module depends on another reactor module not in the 
current session, POM resolution may hit that repo. Today, the main POM path 
contains the build POM, which can include Maven-4 build-time constructs and be 
invalid as a repository POM (e.g., missing parent.*). As a result, dependency 
resolution can fail with fatal model errors.
    
    Teach ReactorReader to prefer the consumer POM (classifier=consumer) for 
POM artifacts when present in the project-local repo, falling back to the main 
POM otherwise. This avoids consuming a build POM from the project-local repo 
without changing the repo contents or layout.
    
    * Fix ReactorReader to prefer consumer POMs over build POMs
    
    When building modules in isolation (outside of the full reactor), the
    ReactorReader should prefer consumer POMs from the project-local repository
    over build POMs to avoid invalid POM elements like <parent />.
    
    The findModel method now:
    1. First checks if the project is in the current reactor session
    2. If not found, looks for a consumer POM in the project-local repository
    3. Uses the same consumer POM preference logic as 
findInProjectLocalRepository
    
    This eliminates 'invalid POM' warnings when building modules in isolation
    while maintaining backward compatibility for reactor builds.
    
    Fixes gh-11084
    
    * Fix
---
 .../main/java/org/apache/maven/ReactorReader.java  | 12 +++++
 ...Tgh11084ReactorReaderPreferConsumerPomTest.java | 51 ++++++++++++++++++++++
 .../org/apache/maven/it/TestSuiteOrdering.java     |  1 +
 .../a/pom.xml                                      | 33 ++++++++++++++
 .../a/src/main/java/a/A.java                       | 30 +++++++++++++
 .../b/pom.xml                                      | 32 ++++++++++++++
 .../b/src/main/java/b/B.java                       | 30 +++++++++++++
 .../pom.xml                                        | 30 +++++++++++++
 8 files changed, 219 insertions(+)

diff --git a/impl/maven-core/src/main/java/org/apache/maven/ReactorReader.java 
b/impl/maven-core/src/main/java/org/apache/maven/ReactorReader.java
index db2efa7720..fdca07ee80 100644
--- a/impl/maven-core/src/main/java/org/apache/maven/ReactorReader.java
+++ b/impl/maven-core/src/main/java/org/apache/maven/ReactorReader.java
@@ -330,6 +330,18 @@ private static boolean isTestArtifact(Artifact artifact) {
     }
 
     private File findInProjectLocalRepository(Artifact artifact) {
+        // Prefer the consumer POM when resolving POMs from the project-local 
repository,
+        // to avoid treating a build POM as a repository (consumer) POM.
+        if ("pom".equals(artifact.getExtension())) {
+            String classifier = artifact.getClassifier();
+            if (classifier == null || classifier.isEmpty()) {
+                Path consumer = getArtifactPath(
+                        artifact.getGroupId(), artifact.getArtifactId(), 
artifact.getBaseVersion(), "consumer", "pom");
+                if (Files.isRegularFile(consumer)) {
+                    return consumer.toFile();
+                }
+            }
+        }
         Path target = getArtifactPath(artifact);
         return Files.isRegularFile(target) ? target.toFile() : null;
     }
diff --git 
a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh11084ReactorReaderPreferConsumerPomTest.java
 
b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh11084ReactorReaderPreferConsumerPomTest.java
new file mode 100644
index 0000000000..647333abfd
--- /dev/null
+++ 
b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh11084ReactorReaderPreferConsumerPomTest.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.it;
+
+import java.io.File;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * This is a test set for GH-11084.
+ */
+class MavenITgh11084ReactorReaderPreferConsumerPomTest extends 
AbstractMavenIntegrationTestCase {
+    MavenITgh11084ReactorReaderPreferConsumerPomTest() {
+        super("[4.0.0-rc-2,)");
+    }
+
+    @Test
+    void partialReactorShouldResolveUsingConsumerPom() throws Exception {
+        File testDir = 
extractResources("/gh-11084-reactorreader-prefer-consumer-pom");
+
+        // First build module a to populate project-local-repo with artifacts 
including consumer POM
+        Verifier v1 = newVerifier(testDir.getAbsolutePath());
+        v1.addCliArguments("clean", "package", "-X");
+        v1.setLogFileName("log-1.txt");
+        v1.execute();
+        v1.verifyErrorFreeLog();
+
+        // Now build only module b; ReactorReader should pick consumer POM 
from project-local-repo
+        Verifier v2 = newVerifier(testDir.getAbsolutePath());
+        v2.setLogFileName("log-2.txt");
+        v2.addCliArguments("clean", "compile", "-f", "b", "-X");
+        v2.execute();
+        v2.verifyErrorFreeLog();
+    }
+}
diff --git 
a/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java 
b/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java
index 23a6e332ab..ecfec0145c 100644
--- a/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java
+++ b/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java
@@ -103,6 +103,7 @@ public TestSuiteOrdering() {
          * the tests are to finishing. Newer tests are also more likely to 
fail, so this is
          * a fail fast technique as well.
          */
+        
suite.addTestSuite(MavenITgh11084ReactorReaderPreferConsumerPomTest.class);
         
suite.addTestSuite(MavenITgh10312TerminallyDeprecatedMethodInGuiceTest.class);
         suite.addTestSuite(MavenITgh10937QuotedPipesInMavenOptsTest.class);
         
suite.addTestSuite(MavenITgh2532DuplicateDependencyEffectiveModelTest.class);
diff --git 
a/its/core-it-suite/src/test/resources/gh-11084-reactorreader-prefer-consumer-pom/a/pom.xml
 
b/its/core-it-suite/src/test/resources/gh-11084-reactorreader-prefer-consumer-pom/a/pom.xml
new file mode 100644
index 0000000000..11ba754ca1
--- /dev/null
+++ 
b/its/core-it-suite/src/test/resources/gh-11084-reactorreader-prefer-consumer-pom/a/pom.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.1.0";>
+  <parent />
+
+  <artifactId>a</artifactId>
+  <packaging>jar</packaging>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-utils</artifactId>
+      <version>4.0.2</version>
+    </dependency>
+  </dependencies>
+</project>
diff --git 
a/its/core-it-suite/src/test/resources/gh-11084-reactorreader-prefer-consumer-pom/a/src/main/java/a/A.java
 
b/its/core-it-suite/src/test/resources/gh-11084-reactorreader-prefer-consumer-pom/a/src/main/java/a/A.java
new file mode 100644
index 0000000000..6e4af4118b
--- /dev/null
+++ 
b/its/core-it-suite/src/test/resources/gh-11084-reactorreader-prefer-consumer-pom/a/src/main/java/a/A.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package a;
+
+import java.io.IOException;
+import java.nio.file.Path;
+
+import org.codehaus.plexus.util.io.CachingOutputStream;
+
+public class A {
+    public static CachingOutputStream newCachingOutputStream(Path p) throws 
IOException {
+        return new CachingOutputStream(p);
+    }
+}
diff --git 
a/its/core-it-suite/src/test/resources/gh-11084-reactorreader-prefer-consumer-pom/b/pom.xml
 
b/its/core-it-suite/src/test/resources/gh-11084-reactorreader-prefer-consumer-pom/b/pom.xml
new file mode 100644
index 0000000000..67fdb8e0dd
--- /dev/null
+++ 
b/its/core-it-suite/src/test/resources/gh-11084-reactorreader-prefer-consumer-pom/b/pom.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.1.0";>
+
+  <parent />
+
+  <artifactId>b</artifactId>
+  <packaging>jar</packaging>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.its.gh11084</groupId>
+      <artifactId>a</artifactId>
+    </dependency>
+  </dependencies>
+</project>
diff --git 
a/its/core-it-suite/src/test/resources/gh-11084-reactorreader-prefer-consumer-pom/b/src/main/java/b/B.java
 
b/its/core-it-suite/src/test/resources/gh-11084-reactorreader-prefer-consumer-pom/b/src/main/java/b/B.java
new file mode 100644
index 0000000000..8198e69cd2
--- /dev/null
+++ 
b/its/core-it-suite/src/test/resources/gh-11084-reactorreader-prefer-consumer-pom/b/src/main/java/b/B.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package b;
+
+import java.nio.file.Paths;
+
+import a.A;
+import org.codehaus.plexus.util.io.CachingOutputStream;
+
+public class B {
+    public static void v() throws Exception {
+        try (CachingOutputStream is = 
A.newCachingOutputStream(Paths.get("."))) {}
+    }
+}
diff --git 
a/its/core-it-suite/src/test/resources/gh-11084-reactorreader-prefer-consumer-pom/pom.xml
 
b/its/core-it-suite/src/test/resources/gh-11084-reactorreader-prefer-consumer-pom/pom.xml
new file mode 100644
index 0000000000..068bf84c5f
--- /dev/null
+++ 
b/its/core-it-suite/src/test/resources/gh-11084-reactorreader-prefer-consumer-pom/pom.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.1.0"; root="true">
+  <groupId>org.apache.maven.its.gh11084</groupId>
+  <artifactId>reactor-root</artifactId>
+  <version>1.0.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <modules>
+    <module>a</module>
+    <module>b</module>
+  </modules>
+</project>

Reply via email to