Spring Boot gradle build - invalid source release: 11
Asked Answered
J

4

14

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:

  1. Settings - Build, Execution, Deployment - Build Tools - Gradle
    -> set to 11. enter image description here

  2. Settings - Build, Execution, Deployment - Compiler - Java Compiler - Project bytecode version
    -> set to 11. enter image description here

  3. java -version command on IntelliJ Terminal
    -> set to 11.0.12
    enter image description here

  4. Project Structure - Project Settings - Project - Project SDK: -> set to 11.
    enter image description here

  5. Project Structure - Project Settings - Modules - Module SDK: -> set to 11.
    enter image description here

  6. Project Structure - Platform Settings - SDKs - JDK home path:
    -> set to 11.
    enter image description here

  7. System Environment path - JAVA_HOME
    -> set to 11.
    enter image description here

  8. build.gradle - sourceCompatibility, targetCompatibility
    -> set to 11.
    enter image description here

After all of this when I run

./gradlew build



result
enter image description here

I think I've done everything possible. Is there any other settings that I can try ??

Journalize answered 12/12, 2021 at 2:13 Comment(0)
M
16

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
Mckinnon answered 12/12, 2021 at 20:3 Comment(2)
had problem with STS, commandline argument approach worked for me i.e. solution2 on windows, thanksRadiocommunication
Thanks. It seems like host env variable was the issue at the end. For intelliJ users; File -> Settings -> Tools -> Terminal -> Environment variables: JAVA_HOME=C:\user\desired\jdk\path. In this way you can set the JDK path in local project scope. Don't forget to close and re-open terminal tab.Journalize
C
1

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.

Convulsive answered 6/2, 2022 at 3:11 Comment(0)
I
0

In my case I had to remove the .gradle folder, likely cache was causing issues

Ixia answered 8/11, 2023 at 10:28 Comment(0)
D
-5

Set project jdk to 1.8 instants 11

Demakis answered 12/12, 2021 at 3:24 Comment(2)
set to 1.8 ? Is it impossible to build a project with jdk 11 ?Journalize
some lib not support 11 that's why you need to change it to 1.8Demakis

© 2022 - 2024 — McMap. All rights reserved.