You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2026/08/29 22:14:45 UTC
(maven) branch maven-4.0.x updated: fix: interpolate properties in module/subproject path before filesystem resolution (backport #12734)
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch maven-4.0.x
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/maven-4.0.x by this push:
new d2957d8479 fix: interpolate properties in module/subproject path before filesystem resolution (backport #12734)
d2957d8479 is described below
commit d2957d84794097ee325d582bcfb0b91161ecd110
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Sun Aug 30 00:14:38 2026 +0200
fix: interpolate properties in module/subproject path before filesystem resolution (backport #12734)
* fix: interpolate properties in module/subproject path before filesystem resolution (#12734)
* fix: interpolate properties in module/subproject path before filesystem resolution
* fix: address review feedback for module path interpolation
- Fix property lookup precedence: user → model → system (was inverted)
- Use Interpolator.chain() instead of manual lambda for consistency
- Remove redundant null guard on interpolator.interpolate() result
- Fix comment reference from MNG-XXXX to #12729
- Add regression integration test for gh-12729
Co-Authored-By: Claude Opus 4.6 <no...@anthropic.com>
---------
Co-authored-by: Guillaume Nodet <gn...@gmail.com>
Co-authored-by: Claude Opus 4.6 <no...@anthropic.com>
* fix: adapt IT test to maven-4.0.x AbstractMavenIntegrationTestCase API
The base class on maven-4.0.x requires a version range constructor
argument and uses File/String instead of Path for extractResources
and newVerifier.
Co-Authored-By: Claude Opus 4.6 <no...@anthropic.com>
---------
Co-authored-by: water <67...@qq.com>
Co-authored-by: Claude Opus 4.6 <no...@anthropic.com>
---
.../maven/impl/model/DefaultModelBuilder.java | 12 ++++
...gh12729ModulePathPropertyInterpolationTest.java | 69 ++++++++++++++++++++++
.../child/pom.xml | 30 ++++++++++
.../pom.xml | 35 +++++++++++
4 files changed, 146 insertions(+)
diff --git a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java
index 46602d0c02..26b6cb6eb1 100644
--- a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java
+++ b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java
@@ -992,6 +992,18 @@ private void loadFilePom(
continue;
}
+ // #12729: interpolate properties in the subproject/module path (e.g.
+ // <module>./../module/pom${version-discriminator}.xml</module>) before
+ // resolving it against the filesystem. Model-wide interpolation happens
+ // later in the build, but module paths must be resolved here, so we
+ // interpolate just the path against the user, model and system properties.
+ subproject = interpolator.interpolate(
+ subproject,
+ Interpolator.chain(
+ request.getUserProperties()::get,
+ activated.getProperties()::get,
+ request.getSystemProperties()::get));
+
subproject = subproject.replace('\\', File.separatorChar).replace('/', File.separatorChar);
Path rawSubprojectFile = modelProcessor.locateExistingPom(pomDirectory.resolve(subproject));
diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12729ModulePathPropertyInterpolationTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12729ModulePathPropertyInterpolationTest.java
new file mode 100644
index 0000000000..f536571824
--- /dev/null
+++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12729ModulePathPropertyInterpolationTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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;
+
+/**
+ * Integration test for <a href="https://github.com/apache/maven/issues/12729">#12729</a>.
+ * Verifies that properties in {@code <module>} (or {@code <subproject>}) paths of aggregator
+ * POMs are interpolated before filesystem resolution.
+ *
+ * <p>Maven 3 interpolated {@code ${property}} references in module paths, but Maven 4 lost
+ * this behaviour because the module path is resolved against the filesystem before model-wide
+ * interpolation runs. The fix performs a targeted early interpolation of the path string
+ * against user, model and system properties.
+ */
+class MavenITgh12729ModulePathPropertyInterpolationTest extends AbstractMavenIntegrationTestCase {
+
+ MavenITgh12729ModulePathPropertyInterpolationTest() {
+ super("[4.0.0-rc-1,)");
+ }
+
+ /**
+ * Verify that a POM-defined property in a {@code <module>} path is interpolated correctly.
+ */
+ @Test
+ void testModulePathWithPomProperty() throws Exception {
+ File testDir = extractResources("/gh-12729-module-path-property-interpolation");
+
+ Verifier verifier = newVerifier(testDir.getAbsolutePath());
+ verifier.addCliArgument("validate");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+ }
+
+ /**
+ * Verify that a user property ({@code -D}) overrides a POM property in a module path,
+ * following Maven's user → model → system property precedence.
+ */
+ @Test
+ void testModulePathWithUserPropertyOverride() throws Exception {
+ File testDir = extractResources("/gh-12729-module-path-property-interpolation");
+
+ Verifier verifier = newVerifier(testDir.getAbsolutePath());
+ // The POM defines child-dir=child; this override should also resolve to "child"
+ verifier.addCliArgument("-Dchild-dir=child");
+ verifier.addCliArgument("validate");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+ }
+}
diff --git a/its/core-it-suite/src/test/resources/gh-12729-module-path-property-interpolation/child/pom.xml b/its/core-it-suite/src/test/resources/gh-12729-module-path-property-interpolation/child/pom.xml
new file mode 100644
index 0000000000..b2f0ac6fd2
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/gh-12729-module-path-property-interpolation/child/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.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.its.gh12729</groupId>
+ <artifactId>module-path-interpolation-parent</artifactId>
+ <version>0.1</version>
+ </parent>
+
+ <artifactId>module-path-interpolation-child</artifactId>
+</project>
diff --git a/its/core-it-suite/src/test/resources/gh-12729-module-path-property-interpolation/pom.xml b/its/core-it-suite/src/test/resources/gh-12729-module-path-property-interpolation/pom.xml
new file mode 100644
index 0000000000..74c9ff45bc
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/gh-12729-module-path-property-interpolation/pom.xml
@@ -0,0 +1,35 @@
+<?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.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.gh12729</groupId>
+ <artifactId>module-path-interpolation-parent</artifactId>
+ <version>0.1</version>
+ <packaging>pom</packaging>
+
+ <properties>
+ <child-dir>child</child-dir>
+ </properties>
+
+ <modules>
+ <module>${child-dir}</module>
+ </modules>
+</project>