gnodet commented on code in PR #13056:
URL: https://github.com/apache/maven/pull/13056#discussion_r3941981014


##########
apache-maven/src/assembly/maven/bin/mvn.cmd:
##########
@@ -74,13 +74,26 @@ if not exist "%JAVACMD%" (
   goto error
 )
 
-@REM Check Java version by testing the Java 17+ flag
-"%JAVACMD%" --enable-native-access=ALL-UNNAMED -version >nul 2>&1
-if ERRORLEVEL 1 (
-    echo Error: Apache Maven 4.x requires Java 17 or newer to run. >&2
-    "%JAVACMD%" -version >&2
-    echo Please upgrade your Java installation or set JAVA_HOME to point to a 
compatible JDK. >&2
-    goto error
+@REM Scan the arguments for version/quiet flags so that version-only
+@REM invocations can be answered without starting Maven itself; the Java-17
+@REM gate below then doubles as the settings probe used to render the banner.
+set "IS_VERSION_AND_EXIT="
+set "IS_SHOW_VERSION="
+set "IS_QUIET="
+set "IS_VERBOSE="
+set "IS_MAIN_OVERRIDE="
+for %%a in (%*) do (
+  if "%%~a"=="-v" set "IS_VERSION_AND_EXIT=1"
+  if "%%~a"=="--version" set "IS_VERSION_AND_EXIT=1"
+  if "%%~a"=="-V" set "IS_SHOW_VERSION=1"
+  if "%%~a"=="--show-version" set "IS_SHOW_VERSION=1"
+  if "%%~a"=="-q" set "IS_QUIET=1"
+  if "%%~a"=="--quiet" set "IS_QUIET=1"
+  if "%%~a"=="-X" set "IS_VERBOSE=1"
+  if "%%~a"=="--debug" set "IS_VERBOSE=1"
+  if "%%~a"=="--enc" set "IS_MAIN_OVERRIDE=1"
+  if "%%~a"=="--shell" set "IS_MAIN_OVERRIDE=1"
+  if "%%~a"=="--up" set "IS_MAIN_OVERRIDE=1"
 )
 
 :chkMHome

Review Comment:
   ⚠️ **Warning:** `for %%a in (%*)` in batch splits tokens on `=` (among other 
delimiters), so an argument like `-Dfoo=-v` would be split into `-Dfoo` and 
`-v`, causing a false-positive that triggers `IS_VERSION_AND_EXIT`.
   
   This means `mvn -Dfoo=-v compile` would print the version and exit instead 
of running the build. Similarly, `-Dverbose=--version` would trigger it.
   
   The Unix script doesn't have this problem because `for arg in "$@"` 
preserves argument boundaries.
   
   A safer approach would be to use `shift`-based parsing or `%1`/`%2`/... 
positional parameters with a `:parseArgs` label loop, which respects quoted 
argument boundaries.



##########
apache-maven/src/assembly/maven/bin/mvn.cmd:
##########
@@ -74,13 +74,26 @@ if not exist "%JAVACMD%" (
   goto error
 )
 
-@REM Check Java version by testing the Java 17+ flag
-"%JAVACMD%" --enable-native-access=ALL-UNNAMED -version >nul 2>&1
-if ERRORLEVEL 1 (
-    echo Error: Apache Maven 4.x requires Java 17 or newer to run. >&2
-    "%JAVACMD%" -version >&2
-    echo Please upgrade your Java installation or set JAVA_HOME to point to a 
compatible JDK. >&2
-    goto error
+@REM Scan the arguments for version/quiet flags so that version-only
+@REM invocations can be answered without starting Maven itself; the Java-17
+@REM gate below then doubles as the settings probe used to render the banner.
+set "IS_VERSION_AND_EXIT="
+set "IS_SHOW_VERSION="
+set "IS_QUIET="
+set "IS_VERBOSE="
+set "IS_MAIN_OVERRIDE="
+for %%a in (%*) do (
+  if "%%~a"=="-v" set "IS_VERSION_AND_EXIT=1"
+  if "%%~a"=="--version" set "IS_VERSION_AND_EXIT=1"
+  if "%%~a"=="-V" set "IS_SHOW_VERSION=1"
+  if "%%~a"=="--show-version" set "IS_SHOW_VERSION=1"
+  if "%%~a"=="-q" set "IS_QUIET=1"
+  if "%%~a"=="--quiet" set "IS_QUIET=1"
+  if "%%~a"=="-X" set "IS_VERBOSE=1"
+  if "%%~a"=="--debug" set "IS_VERBOSE=1"
+  if "%%~a"=="--enc" set "IS_MAIN_OVERRIDE=1"
+  if "%%~a"=="--shell" set "IS_MAIN_OVERRIDE=1"
+  if "%%~a"=="--up" set "IS_MAIN_OVERRIDE=1"
 )
 
 :chkMHome

Review Comment:
   💡 **Note:** Unlike the Unix script which handles compact options (`-qv`, 
`-vX`, etc. via `-[qvVXe]*`), the Windows script only matches exact single 
options. This means `-qv` on Windows won't trigger the fast path and will fall 
through to the full JVM launch. Not a bug (Maven will still work), but a 
behavioral inconsistency between platforms.



##########
apache-maven/src/main/resources/org/apache/maven/messages/maven.version.properties:
##########
@@ -0,0 +1,22 @@
+# 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.
+
+buildNumber=${buildNumber}
+version=${project.version}
+distributionId=${distributionId}
+distributionShortName=${distributionShortName}
+distributionName=${distributionName}

Review Comment:
   💡 **Nit:** File is missing a trailing newline. While properties files don't 
strictly require it, POSIX text files should end with a newline, and git flags 
this. Also, `distributionId` is defined here but never read by either the Unix 
or Windows script — consider removing it or documenting its intended consumer.
   
   ```suggestion
   distributionName=${distributionName}
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to