fail clearly on too-new JDK (#819)

Gradle will give a very confusing error, let's make it absolutely clear.

Co-authored-by: Dawid Weiss <dawid.weiss@carrotsearch.com>
This commit is contained in:
Robert Muir 2022-04-21 09:22:26 -04:00 committed by GitHub
parent d6461eab0b
commit c897aac077
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 5 deletions

View File

@ -42,14 +42,22 @@ public class WrapperDownloader {
public static void main(String[] args) { public static void main(String[] args) {
if (args.length != 1) { if (args.length != 1) {
System.err.println("Usage: java WrapperDownloader.java <destination>"); System.err.println("Usage: java WrapperDownloader.java <destination>");
System.exit(1); System.exit(2);
} }
try { try {
checkVersion();
new WrapperDownloader().run(Paths.get(args[0])); new WrapperDownloader().run(Paths.get(args[0]));
} catch (Exception e) { } catch (Exception e) {
System.err.println("ERROR: " + e.getMessage()); System.err.println("ERROR: " + e.getMessage());
System.exit(1); System.exit(3);
}
}
public static void checkVersion() {
int major = Runtime.getRuntime().version().feature();
if (major != 17) {
throw new IllegalStateException("java version be exactly 17, your version: " + major);
} }
} }

10
gradlew vendored
View File

@ -121,9 +121,13 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
fi fi
GRADLE_WRAPPER_JAR="$APP_HOME/gradle/wrapper/gradle-wrapper.jar" GRADLE_WRAPPER_JAR="$APP_HOME/gradle/wrapper/gradle-wrapper.jar"
if ! "$JAVACMD" $JAVA_OPTS --source 11 "$APP_HOME/buildSrc/src/main/java/org/apache/lucene/gradle/WrapperDownloader.java" "$GRADLE_WRAPPER_JAR" ; then "$JAVACMD" $JAVA_OPTS --source 11 "$APP_HOME/buildSrc/src/main/java/org/apache/lucene/gradle/WrapperDownloader.java" "$GRADLE_WRAPPER_JAR"
echo "\nSomething went wrong. Make sure you're using Java 11 or later." WRAPPER_STATUS=$?
exit $? if [ "$WRAPPER_STATUS" -eq 1 ]; then
echo "ERROR: Something went wrong. Make sure you're using Java 17."
exit $WRAPPER_STATUS
elif [ "$WRAPPER_STATUS" -ne 0 ]; then
exit $WRAPPER_STATUS
fi fi
CLASSPATH=$GRADLE_WRAPPER_JAR CLASSPATH=$GRADLE_WRAPPER_JAR

3
gradlew.bat vendored
View File

@ -94,6 +94,9 @@ IF NOT EXIST "%DIRNAME%\gradle.properties" SET GRADLE_DAEMON_CTRL=--no-daemon
if "%ERRORLEVEL%"=="0" goto mainEnd if "%ERRORLEVEL%"=="0" goto mainEnd
:fail :fail
@rem https://github.com/apache/lucene/pull/819
echo Error: Something went wrong. Make sure you're using Java 17.
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code! rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1