OnJava8-Examples
OnJava8-Examples copied to clipboard
Build failed when running `gradlew run`
I used git command to clone this repository, and then execute gradlew run in cmd. Got this problem:
H:\java\onJava\Onjava8-examples>gradlew run
FAILURE: Build failed with an exception.
* What went wrong:
Could not open settings generic class cache for settings file 'H:\java\onJava\Onjava8-examples\settings.gradle' (C:\Users\hosealle\.gradle\caches\6.8.1\scripts\75ld31xr8xs8bcp4ekz1dgyh0).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 61
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 936ms
You are running Gradle with JDK 17 (based on the error message "Unsupported class file major version 61").
Following the Gradle compatibility matrix JDK 15 is the highest supported Java version for Gradle versions lower than 7.0. The wrapper in the repository is configured to be version 6.8.1.
To solve the issue, the easiest (without changing anything in the repository) would be to run gradlew with a JDK version lower than 16.
Another possibility could be to update the Gradle wrapper to version 7.3 (as this one would support JDK 17). But updating the wrapper probably require other changes too.
I found the solution worked for me: modify the file named java.gradle in the gradle subfolder, change the sourceCompatibility and targetCompatibility to the jdk version you're using, then everything works fine.

PS: version above Java14(or 15, 16?) needs higher version of gradle, so the Java 17 is not able to be used in this project.