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/07/24 06:54:13 UTC

(maven) branch master updated: Fix #12507: preserve unresolved ${...} in CLI -D values (Maven 3 semantics) (#12523)

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 828e528f7d Fix #12507: preserve unresolved ${...} in CLI -D values (Maven 3 semantics) (#12523)
828e528f7d is described below

commit 828e528f7d779b01be91d704ad2ff11a21f9c80a
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Fri Jul 24 08:54:08 2026 +0200

    Fix #12507: preserve unresolved ${...} in CLI -D values (Maven 3 semantics) (#12523)
    
    * Add failing IT for #12507 (CLI ${...} param wipe)
    
    MavenITgh12507CliParamNestedInterpolationTest shows that ${user.dir}
    and ${project.build.directory} inside a -D-supplied plugin parameter
    value are replaced with the empty string at CLI parse time
    (BaseParser.populateUserProperties interpolates user-specified
    properties with defaultsToEmpty=true against a paths-only callback),
    while Maven 3 resolves such expressions at mojo configuration time.
    
    Co-Authored-By: Claude Fable 5 <no...@anthropic.com>
    
    * Fix #12507: dont wipe unresolved ${...} in -D values
    
    BaseParser.populateUserProperties interpolated user-specified
    properties with defaultsToEmpty=true against a paths-only callback,
    silently replacing every expression it could not resolve (system
    properties, project.* references) with the empty string. Pass
    defaultsToEmpty=false so unresolved placeholders stay literal and are
    evaluated later with full session/project context by the plugin
    parameter expression evaluator -- restoring Maven 3 semantics for
    values like -DaltDeploymentRepository=id::file://${project.build.directory}/x.
    
    Co-Authored-By: Claude Fable 5 <no...@anthropic.com>
    
    * Update gh-11978 IT to expect Maven 3 semantics for unknown placeholders
    
    The previous assertion expected unknown ${...} in CLI -D values to be
    emptied, but that was an unintended side effect of #2480 (which only
    meant to add session.topDirectory interpolation). Maven 3 leaves
    unknown placeholders literal — update the assertion to match.
    
    Co-Authored-By: Claude Opus 4.6 <no...@anthropic.com>
    
    ---------
    
    Co-authored-by: Gerd Aschemann <as...@apache.org>
    Co-authored-by: Claude Fable 5 <no...@anthropic.com>
---
 .../org/apache/maven/cling/invoker/BaseParser.java |  6 +-
 .../it/MavenITgh11978PlaceholderInCliArgTest.java  |  6 +-
 ...enITgh12507CliParamNestedInterpolationTest.java | 73 ++++++++++++++++++++++
 .../pom.xml                                        | 56 +++++++++++++++++
 4 files changed, 138 insertions(+), 3 deletions(-)

diff --git a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/BaseParser.java b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/BaseParser.java
index bd8a6e6693..9a740753bb 100644
--- a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/BaseParser.java
+++ b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/BaseParser.java
@@ -438,7 +438,11 @@ protected Map<String, String> populateUserProperties(LocalContext context) {
         Map<String, String> userSpecifiedProperties = context.options != null
                 ? new HashMap<>(context.options.userProperties().orElse(new HashMap<>()))
                 : new HashMap<>();
-        createInterpolator().interpolate(userSpecifiedProperties, paths::get);
+        // Resolve only early-available path placeholders (session.topDirectory & co); leave everything
+        // else literal so it can be evaluated later with full session/project context by the
+        // plugin parameter expression evaluator (gh-12507: wiping unresolved ${...} to the empty
+        // string silently broke e.g. -DaltDeploymentRepository=id::file://${project.build.directory}/x).
+        createInterpolator().interpolate(userSpecifiedProperties, paths::get, false);
 
         // ----------------------------------------------------------------------
         // Load config files
diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh11978PlaceholderInCliArgTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh11978PlaceholderInCliArgTest.java
index fde0c7f009..0ddf106ec4 100644
--- a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh11978PlaceholderInCliArgTest.java
+++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh11978PlaceholderInCliArgTest.java
@@ -50,8 +50,10 @@ void testIt() throws Exception {
         verifier.verifyErrorFreeLog(); // primary check: shell crash produces non-zero exit
 
         // Secondary: verify the literal placeholder flowed through Maven.
-        // Maven resolves the unknown ${some.maven.placeholder} to empty.
+        // Unknown ${...} expressions are preserved as literals (Maven 3 semantics, see gh-12507);
+        // they are not replaced with empty strings at CLI parse time.
         Properties props = verifier.loadProperties("target/pom.properties");
-        assertEquals("-value__end-", props.getProperty("project.properties.pom.placeholder"));
+        assertEquals(
+                "-value_${some.maven.placeholder}_end-", props.getProperty("project.properties.pom.placeholder"));
     }
 }
diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12507CliParamNestedInterpolationTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12507CliParamNestedInterpolationTest.java
new file mode 100644
index 0000000000..f37303fea8
--- /dev/null
+++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh12507CliParamNestedInterpolationTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.nio.file.Path;
+import java.util.Properties;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * This is a test set for <a href="https://github.com/apache/maven/issues/12507">gh-12507</a>:
+ * {@code ${...}} expressions inside CLI-supplied plugin parameter values must be resolved
+ * against the session/project context (Maven 3 semantics), not silently replaced with the
+ * empty string. The real-world trigger is
+ * {@code -DaltDeploymentRepository=id::file://${project.build.directory}/deploy}, which under
+ * the regression deploys to the filesystem root ({@code file:///deploy}).
+ */
+class MavenITgh12507CliParamNestedInterpolationTest extends AbstractMavenIntegrationTestCase {
+
+    /**
+     * Verify that a system-property expression inside a CLI-supplied parameter value is resolved.
+     */
+    @Test
+    void testNestedSystemPropertyExpression() throws Exception {
+        Path basedir = extractResources("gh-12507-cli-param-nested-interpolation");
+
+        Verifier verifier = newVerifier(basedir);
+        verifier.addCliArgument("-Dconfig.stringParam=PRE-${user.dir}-POST");
+        verifier.addCliArgument("validate");
+        verifier.execute();
+        verifier.verifyErrorFreeLog();
+
+        Properties props = verifier.loadProperties("target/config.properties");
+        assertEquals("PRE-" + basedir + "-POST", props.getProperty("stringParam"));
+    }
+
+    /**
+     * Verify that a project expression inside a CLI-supplied parameter value is resolved.
+     */
+    @Test
+    void testNestedProjectExpression() throws Exception {
+        Path basedir = extractResources("gh-12507-cli-param-nested-interpolation");
+
+        Verifier verifier = newVerifier(basedir);
+        verifier.addCliArgument("-Dconfig.stringParam=PRE-${project.build.directory}-POST");
+        verifier.addCliArgument("validate");
+        verifier.execute();
+        verifier.verifyErrorFreeLog();
+
+        Properties props = verifier.loadProperties("target/config.properties");
+        assertEquals(
+                "PRE-" + basedir.resolve("target") + "-POST",
+                props.getProperty("stringParam"));
+    }
+}
diff --git a/its/core-it-suite/src/test/resources/gh-12507-cli-param-nested-interpolation/pom.xml b/its/core-it-suite/src/test/resources/gh-12507-cli-param-nested-interpolation/pom.xml
new file mode 100644
index 0000000000..668a78a409
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/gh-12507-cli-param-nested-interpolation/pom.xml
@@ -0,0 +1,56 @@
+<?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">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.gh12507</groupId>
+  <artifactId>cli-param-nested-interpolation</artifactId>
+  <version>0.1</version>
+  <packaging>jar</packaging>
+
+  <name>Maven Integration Test :: gh-12507</name>
+  <description>Test that ${...} expressions inside CLI-supplied plugin parameter values (-Dconfig.stringParam=...)
+    are resolved against the session/project context like Maven 3 does, instead of being replaced with the
+    empty string.</description>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.its.plugins</groupId>
+        <artifactId>maven-it-plugin-configuration</artifactId>
+        <version>2.1-SNAPSHOT</version>
+        <configuration>
+          <propertiesFile>target/config.properties</propertiesFile>
+        </configuration>
+        <executions>
+          <execution>
+            <id>test</id>
+            <goals>
+              <goal>config</goal>
+            </goals>
+            <phase>validate</phase>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>