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 03975900cb Fix #12464: Skip MAVEN_ARGS for non-default main classes
(--up, --enc, --shell) (#12465)
03975900cb is described below
commit 03975900cb9ecc0171756ce9acae520606d1a9a0
Author: Guillaume Nodet <[email protected]>
AuthorDate: Sat Jul 11 17:07:29 2026 +0200
Fix #12464: Skip MAVEN_ARGS for non-default main classes (--up, --enc,
--shell) (#12465)
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% %*