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 bad1387892 [MNG-8376] Exit with a nicer error message when running on 
JDK < 17 (#1916)
bad1387892 is described below

commit bad1387892e33362bfe57f10e1401c6dfb72bae1
Author: Guillaume Nodet <gno...@gmail.com>
AuthorDate: Mon Nov 18 10:45:25 2024 +0100

    [MNG-8376] Exit with a nicer error message when running on JDK < 17 (#1916)
---
 apache-maven/src/assembly/maven/bin/mvn     |  7 +++++++
 apache-maven/src/assembly/maven/bin/mvn.cmd | 10 ++++++++++
 2 files changed, 17 insertions(+)

diff --git a/apache-maven/src/assembly/maven/bin/mvn 
b/apache-maven/src/assembly/maven/bin/mvn
index d516a8d93c..5888451f5f 100755
--- a/apache-maven/src/assembly/maven/bin/mvn
+++ b/apache-maven/src/assembly/maven/bin/mvn
@@ -107,6 +107,13 @@ else
   fi
 fi
 
+if ! "$JAVACMD" --enable-native-access=ALL-UNNAMED -version >/dev/null 2>&1; 
then
+  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
+  exit 1
+fi
+
 # traverses directory structure from process work directory to filesystem root
 # first directory with .mvn subdirectory is considered project base directory
 find_maven_basedir() {
diff --git a/apache-maven/src/assembly/maven/bin/mvn.cmd 
b/apache-maven/src/assembly/maven/bin/mvn.cmd
index b5e204cb30..dcc413ce4b 100644
--- a/apache-maven/src/assembly/maven/bin/mvn.cmd
+++ b/apache-maven/src/assembly/maven/bin/mvn.cmd
@@ -69,6 +69,16 @@ if not exist "%JAVACMD%" (
   echo The java.exe command does not exist in PATH nor is JAVA_HOME set, so 
Apache Maven cannot be started. >&2
   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
+)
+
 :chkMHome
 set "MAVEN_HOME=%~dp0"
 set "MAVEN_HOME=%MAVEN_HOME:~0,-5%"

Reply via email to