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

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

commit baca50e925e61cb7bd0888093ad3c3789bb7fc20
Author: Guillaume Nodet <[email protected]>
AuthorDate: Mon May 18 23:59:40 2026 +0200

    Fix #12085: add regression tests for version inheritance from remote parent
    
    The issue reported a null root artifact error when building projects
    that inherit version from a remote parent POM. Investigation showed
    the actual cause was uninterpolated repository expressions leaking
    through to the CollectRequest validator, which was already fixed by
    commits 9332ad3d55 and cee3c33c74.
    
    Add regression tests covering both single-project and multi-module
    builds with version inherited from a remote parent POM (different
    groupId, empty relativePath).
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
---
 .../project/DefaultMavenProjectBuilderTest.java    | 39 ++++++++++++++++++++++
 .../org/test/parent-pom/1.0/parent-pom-1.0.pom     | 31 +++++++++++++++++
 .../child/pom.xml                                  | 12 +++++++
 .../pom.xml                                        | 10 ++++++
 .../parent-version-inherited-from-remote/pom.xml   | 12 +++++++
 5 files changed, 104 insertions(+)

diff --git 
a/impl/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
 
b/impl/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
index 0dee2323a6..863bfcf898 100644
--- 
a/impl/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
+++ 
b/impl/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
@@ -700,4 +700,43 @@ public void testEmptyModulesElementPreventsDiscovery() 
throws Exception {
         // The modules list should be empty since we explicitly defined an 
empty <modules /> element
         assertTrue(parent.getModel().getDelegate().getModules().isEmpty());
     }
+
+    @Test
+    void testVersionInheritedFromRemoteParent() throws Exception {
+        File f1 = 
getTestFile("src/test/resources/projects/parent-version-inherited-from-remote/pom.xml");
+        MavenProject project = getProject(f1);
+
+        assertNotNull(project, "project should not be null");
+        assertEquals("1.0", project.getVersion(), "version should be inherited 
from remote parent");
+        assertNotNull(project.getArtifact(), "project artifact should not be 
null");
+        assertEquals("1.0", project.getArtifact().getVersion(), "artifact 
version should match inherited version");
+        assertEquals("org.different.group", project.getGroupId(), "groupId 
should be from child POM");
+        assertEquals("child-project", project.getArtifactId(), "artifactId 
should be from child POM");
+    }
+
+    @Test
+    void testVersionInheritedFromRemoteParentMultiModule() throws Exception {
+        File pom = 
getTestFile("src/test/resources/projects/parent-version-inherited-from-remote-multimodule/pom.xml");
+        ProjectBuildingRequest configuration = newBuildingRequest();
+        InternalSession internalSession = 
InternalSession.from(configuration.getRepositorySession());
+        InternalMavenSession mavenSession = 
InternalMavenSession.from(internalSession);
+        mavenSession
+                .getMavenSession()
+                .getRequest()
+                .setRootDirectory(pom.toPath().getParent());
+
+        List<ProjectBuildingResult> results = 
projectBuilder.build(List.of(pom), true, configuration);
+        assertEquals(2, results.size());
+
+        MavenProject child = results.stream()
+                .map(ProjectBuildingResult::getProject)
+                .filter(p -> "child-project".equals(p.getArtifactId()))
+                .findFirst()
+                .orElse(null);
+        assertNotNull(child, "child project should be found");
+        assertEquals("1.0", child.getVersion(), "version should be inherited 
from remote parent");
+        assertNotNull(child.getArtifact(), "child project artifact should not 
be null");
+        assertEquals("1.0", child.getArtifact().getVersion(), "artifact 
version should match inherited version");
+        assertEquals("org.different.group", child.getGroupId(), "groupId 
should be from child POM");
+    }
 }
diff --git 
a/impl/maven-core/src/test/remote-repo/org/test/parent-pom/1.0/parent-pom-1.0.pom
 
b/impl/maven-core/src/test/remote-repo/org/test/parent-pom/1.0/parent-pom-1.0.pom
new file mode 100644
index 0000000000..fd93eabf47
--- /dev/null
+++ 
b/impl/maven-core/src/test/remote-repo/org/test/parent-pom/1.0/parent-pom-1.0.pom
@@ -0,0 +1,31 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.test</groupId>
+  <artifactId>parent-pom</artifactId>
+  <version>1.0</version>
+  <packaging>pom</packaging>
+
+  <repositories>
+    <repository>
+      <id>staging</id>
+      <url>https://repository.example.org/staging</url>
+    </repository>
+  </repositories>
+
+  <profiles>
+    <profile>
+      <id>nightly</id>
+      <activation>
+        <property>
+          <name>nightly</name>
+        </property>
+      </activation>
+      <repositories>
+        <repository>
+          <id>${uninterpolatedRepoId}</id>
+          <url>file://${SNAPSHOTS_PATH}</url>
+        </repository>
+      </repositories>
+    </profile>
+  </profiles>
+</project>
diff --git 
a/impl/maven-core/src/test/resources/projects/parent-version-inherited-from-remote-multimodule/child/pom.xml
 
b/impl/maven-core/src/test/resources/projects/parent-version-inherited-from-remote-multimodule/child/pom.xml
new file mode 100644
index 0000000000..d3c99a4c88
--- /dev/null
+++ 
b/impl/maven-core/src/test/resources/projects/parent-version-inherited-from-remote-multimodule/child/pom.xml
@@ -0,0 +1,12 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.test</groupId>
+    <artifactId>parent-pom</artifactId>
+    <version>1.0</version>
+    <relativePath/>
+  </parent>
+  <groupId>org.different.group</groupId>
+  <artifactId>child-project</artifactId>
+  <!-- no version - inherited from remote parent -->
+</project>
diff --git 
a/impl/maven-core/src/test/resources/projects/parent-version-inherited-from-remote-multimodule/pom.xml
 
b/impl/maven-core/src/test/resources/projects/parent-version-inherited-from-remote-multimodule/pom.xml
new file mode 100644
index 0000000000..80cfd216d3
--- /dev/null
+++ 
b/impl/maven-core/src/test/resources/projects/parent-version-inherited-from-remote-multimodule/pom.xml
@@ -0,0 +1,10 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.test.aggregator</groupId>
+  <artifactId>aggregator</artifactId>
+  <version>1.0</version>
+  <packaging>pom</packaging>
+  <modules>
+    <module>child</module>
+  </modules>
+</project>
diff --git 
a/impl/maven-core/src/test/resources/projects/parent-version-inherited-from-remote/pom.xml
 
b/impl/maven-core/src/test/resources/projects/parent-version-inherited-from-remote/pom.xml
new file mode 100644
index 0000000000..96a5d7325f
--- /dev/null
+++ 
b/impl/maven-core/src/test/resources/projects/parent-version-inherited-from-remote/pom.xml
@@ -0,0 +1,12 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.test</groupId>
+    <artifactId>parent-pom</artifactId>
+    <version>1.0</version>
+    <relativePath/>
+  </parent>
+  <groupId>org.different.group</groupId>
+  <artifactId>child-project</artifactId>
+  <!-- no version - inherited from parent -->
+</project>

Reply via email to