[MNG-8376] Exit with a nicer error message when running on JDK < 17 (#1916)

This commit is contained in:
Guillaume Nodet 2024-11-18 10:45:25 +01:00 committed by GitHub
parent ce096fea3e
commit bad1387892
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View File

@ -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() {

View File

@ -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%"