From bad1387892e33362bfe57f10e1401c6dfb72bae1 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 18 Nov 2024 10:45:25 +0100 Subject: [PATCH] [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%"