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/28 14:30:50 UTC

(maven) branch maven-4.0.x updated: Fix #12868: Restore --define as long option for -D (#12869) (#12899)

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 a37f08a169 Fix #12868: Restore --define as long option for -D (#12869) (#12899)
a37f08a169 is described below

commit a37f08a169f04aa126f9e56c51fb0ee1a5e15310
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Fri Aug 28 16:30:00 2026 +0200

    Fix #12868: Restore --define as long option for -D (#12869) (#12899)
    
    The --define long option was the long form of -D in Maven 3.x but was
    accidentally omitted during the Maven 4 CLI rewrite (CLIng). This restores
    .longOpt("define") on the -D option builder in both the new CLI
    (CommonsCliOptions) and the compat layer (CLIManager).
    
    Co-authored-by: Claude Opus 4.6 <no...@anthropic.com>
---
 .../main/java/org/apache/maven/cli/CLIManager.java |  1 +
 .../maven/cling/invoker/CommonsCliOptions.java     |  1 +
 .../maven/cling/invoker/CommonsCliOptionsTest.java | 56 ++++++++++++++++++++++
 3 files changed, 58 insertions(+)

diff --git a/compat/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java b/compat/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
index 3cc0d38a67..fd2857614c 100644
--- a/compat/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
+++ b/compat/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
@@ -152,6 +152,7 @@ public CLIManager() {
                 .desc("Force the use of an alternate POM file (or directory with pom.xml)")
                 .build());
         options.addOption(Option.builder(Character.toString(SET_USER_PROPERTY))
+                .longOpt("define")
                 .numberOfArgs(2)
                 .valueSeparator('=')
                 .desc("Define a user property")
diff --git a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/CommonsCliOptions.java b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/CommonsCliOptions.java
index c417f24f40..037e2bccee 100644
--- a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/CommonsCliOptions.java
+++ b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/CommonsCliOptions.java
@@ -350,6 +350,7 @@ protected void prepareOptions(org.apache.commons.cli.Options options) {
                     .desc("Display help information")
                     .get());
             options.addOption(Option.builder(USER_PROPERTY)
+                    .longOpt("define")
                     .numberOfArgs(2)
                     .valueSeparator('=')
                     .desc("Define a user property")
diff --git a/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/CommonsCliOptionsTest.java b/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/CommonsCliOptionsTest.java
new file mode 100644
index 0000000000..254631846c
--- /dev/null
+++ b/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/CommonsCliOptionsTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.cling.invoker;
+
+import java.util.Map;
+
+import org.apache.commons.cli.ParseException;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class CommonsCliOptionsTest {
+
+    @Test
+    void shortPropertyOption() throws ParseException {
+        CommonsCliOptions options = CommonsCliOptions.parse("test", new String[] {"-Dfoo=bar"});
+        assertTrue(options.userProperties().isPresent());
+        Map<String, String> props = options.userProperties().get();
+        assertEquals("bar", props.get("foo"));
+    }
+
+    @Test
+    void longDefineOption() throws ParseException {
+        CommonsCliOptions options = CommonsCliOptions.parse("test", new String[] {"--define", "foo=bar"});
+        assertTrue(options.userProperties().isPresent());
+        Map<String, String> props = options.userProperties().get();
+        assertEquals("bar", props.get("foo"));
+    }
+
+    @Test
+    void longDefineOptionMultiple() throws ParseException {
+        CommonsCliOptions options =
+                CommonsCliOptions.parse("test", new String[] {"--define", "foo=bar", "--define", "baz=qux"});
+        assertTrue(options.userProperties().isPresent());
+        Map<String, String> props = options.userProperties().get();
+        assertEquals("bar", props.get("foo"));
+        assertEquals("qux", props.get("baz"));
+    }
+}