'Spring Boot gradle build - invalid source release: 11
I am trying to build my spring boot project with this command:
./gradlew build
But it continuously throws this error:
'Execution failed for task ':compileJava'. invalid source release: 11'.
My project is using Java version 11, and the IntelliJ Java version is set to 11 as well.
This is the Java version settings on my IntelliJ that I have done so far:
Settings - Build, Execution, Deployment - Build Tools - Gradle
-> set to 11.Settings - Build, Execution, Deployment - Compiler - Java Compiler - Project bytecode version
-> set to 11.java -version command on IntelliJ Terminal
-> set to 11.0.12Project Structure - Project Settings - Project - Project SDK: -> set to 11.
Project Structure - Project Settings - Modules - Module SDK: -> set to 11.
Project Structure - Platform Settings - SDKs - JDK home path:
-> set to 11.build.gradle - sourceCompatibility, targetCompatibility
-> set to 11.
After all of this when I run
./gradlew build
I think I've done everything possible. Is there any other settings that I can try ??
Solution 1:[1]
There are 2 solutions. The problem is likely happening because Gradle Wrapper tried to find JDK 11 in Java_home and failed to find it there. I don't think it's because you are using some old deprecated dependencies that don't support jdk11.
Solution1
Explicitly mention the JDK you want to use on terminal. For example, instead of
./gradlew build
Use
./gradlew build -Dorg.gradle.java.home=yourjdk11homepath
Your path might be something like:
C:\\Program Files\\OpenJDK\\jdk-11.0.3
Solution 2
If you don't want to apply solution1 whenever you build project using gradle wrapper, you set the option in gradle.properties file.
On the same directory level as build.gradle and gradlew files, make
gradle.properties
file and write following:
org.gradle.java.home=yourjdk11homepath
Again, your path might be something like:
C:\\Program Files\\OpenJDK\\jdk-11.0.3
Solution 2:[2]
Solution 3:[3]
In my case it's my sdkman which no longer supports adoptopenjdk 11 and the project got renamed to Temurin.
Reference: https://sdkman.io/jdks
So my gradle build was trying to resolve the missing adoptopenjdk 11 and it couldn't. I reinstalled the jdk 11 from Temurin
sdk install java 11.0.14-tem
And voila it solved the build issue and my gradle build is successful.
Solution 4:[4]
Set project jdk to 1.8 instants 11
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Ng?c Hà Nguy?n |
Solution 3 | ArunSelvam P M |
Solution 4 | Jawad Fadel |