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 b3847251fc Fix #12464: Skip MAVEN_ARGS for non-default main classes 
(--up, --enc, --shell) (#12465) (#12466)
b3847251fc is described below

commit b3847251fc79fb0eb3063950215ab47b158ddc80
Author: Guillaume Nodet <[email protected]>
AuthorDate: Sat Jul 11 18:10:43 2026 +0200

    Fix #12464: Skip MAVEN_ARGS for non-default main classes (--up, --enc, 
--shell) (#12465) (#12466)
    
    When MAVEN_MAIN_CLASS is not the default MavenCling (i.e., when using
    --up, --enc, or --shell), skip prepending $MAVEN_ARGS to the command
    line. MAVEN_ARGS may contain build-specific flags like -ntp, -T4, -U
    that are not recognized by MavenUpCling, MavenEncCling, or
    MavenShellCling.
    
    The handle_args function already sets MAVEN_MAIN_CLASS for these
    sub-commands — use that to gate MAVEN_ARGS inclusion.
    
    Co-authored-by: Claude Opus 4.6 <[email protected]>
---
 apache-maven/src/assembly/maven/bin/mvn     | 14 ++++++++++++--
 apache-maven/src/assembly/maven/bin/mvn.cmd |  4 ++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/apache-maven/src/assembly/maven/bin/mvn 
b/apache-maven/src/assembly/maven/bin/mvn
index 85a9a98805..ea5cd1111a 100755
--- a/apache-maven/src/assembly/maven/bin/mvn
+++ b/apache-maven/src/assembly/maven/bin/mvn
@@ -290,10 +290,20 @@ cmd="\"$JAVACMD\" \
 
 if [ -n "$MAVEN_DEBUG_SCRIPT" ]; then
   echo "[DEBUG] Launching JVM with command:" >&2
-  printf '[DEBUG]   %s' "$cmd" >&2; printf ' %s' "$MAVEN_ARGS" >&2; printf ' 
"%s"' "$@" >&2; echo >&2
+  printf '[DEBUG]   %s' "$cmd" >&2
+  if [ "$MAVEN_MAIN_CLASS" = "org.apache.maven.cling.MavenCling" ]; then
+    printf ' %s' "$MAVEN_ARGS" >&2
+  fi
+  printf ' "%s"' "$@" >&2; echo >&2
 fi
 
 # User arguments ("$@") and MAVEN_ARGS are passed outside the eval'd string
 # to preserve literal values (backslashes, ${...} placeholders) without
 # shell re-parsing. Only the base command uses eval for MAVEN_OPTS word 
splitting.
-eval exec "$cmd" '$MAVEN_ARGS' '"$@"'
+# MAVEN_ARGS is only passed for the default Maven build command (MavenCling),
+# not for sub-commands like --up, --enc, or --shell which have their own 
options.
+if [ "$MAVEN_MAIN_CLASS" = "org.apache.maven.cling.MavenCling" ]; then
+  eval exec "$cmd" '$MAVEN_ARGS' '"$@"'
+else
+  eval exec "$cmd" '"$@"'
+fi
diff --git a/apache-maven/src/assembly/maven/bin/mvn.cmd 
b/apache-maven/src/assembly/maven/bin/mvn.cmd
index f6a1413077..74d4a5a984 100644
--- a/apache-maven/src/assembly/maven/bin/mvn.cmd
+++ b/apache-maven/src/assembly/maven/bin/mvn.cmd
@@ -291,6 +291,10 @@ for %%i in ("%MAVEN_HOME%"\boot\plexus-classworlds-*) do 
set LAUNCHER_JAR="%%i"
 set LAUNCHER_CLASS=org.codehaus.plexus.classworlds.launcher.Launcher
 if "%MAVEN_MAIN_CLASS%"=="" @set 
MAVEN_MAIN_CLASS=org.apache.maven.cling.MavenCling
 
+@REM Only pass MAVEN_ARGS for the default Maven build command (MavenCling),
+@REM not for sub-commands like --up, --enc, or --shell which have their own 
options.
+if not "%MAVEN_MAIN_CLASS%"=="org.apache.maven.cling.MavenCling" set 
"MAVEN_ARGS="
+
 if defined MAVEN_DEBUG_SCRIPT (
   echo [DEBUG] Launching JVM with command:
   echo [DEBUG]   "%JAVACMD%" %INTERNAL_MAVEN_OPTS% %MAVEN_OPTS% 
%JVM_CONFIG_MAVEN_OPTS% %MAVEN_DEBUG_OPTS% --enable-native-access=ALL-UNNAMED 
-classpath %LAUNCHER_JAR% "-Dclassworlds.conf=%CLASSWORLDS_CONF%" 
"-Dmaven.home=%MAVEN_HOME%" "-Dmaven.mainClass=%MAVEN_MAIN_CLASS%" 
"-Dlibrary.jline.path=%MAVEN_HOME%\lib\jline-native" 
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %LAUNCHER_CLASS% 
%MAVEN_ARGS% %*

Reply via email to