Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ - Invalid source release: 17

I've created a new Java project in IntelliJ with Gradle that uses Java 17. When running my app it has the error Cause: error: invalid source release: 17.

My Settings

I've installed openjdk-17 through IntelliJ and set it as my Project SDK.

The Project language level has been set to 17 - Sealed types, always-strict floating-point semantics.

enter image description here

In Modules -> Sources I've set the Language level to Project default (17 - Sealed types, always strict floating-point semantics).

modules->sources

In Modules -> Dependencies I've set the Module SDK to Project SDK openjdk-17.

modules->dependencies

In Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler I've set the Project bytecode version to 17.

enter image description here

Gradle

plugins {
    id 'org.springframework.boot' version '2.5.6'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'com.app'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-websocket'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    implementation 'com.fasterxml.jackson.core:jackson-core:2.13.0'
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0'
}

test {
    useJUnitPlatform()
}

I've looked at all of the answers here but I can't seem to fix this. I must be missing something but I can't find it. I've not had any problems using Java 8 or 11.

How do I resolve this?

like image 440
Michael Avatar asked Oct 24 '21 11:10

Michael


People also ask

How do I fix Java warning Source Release 11 requires target release 11?

To Solve Error:java: invalid target release: 11 Error To resolve this issue I've changed File->Project Structure->Modules ->> Language level to 10. And check File -> Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler ->> Project bytecode and Per-module bytecode versions.

What does invalid source release mean?

Error:java: invalid source release: 8. The reason is that your project/module JDK version does not match the intellij project version and below steps to fix it : Open your IntelliJ and navigate to File -> Project Structure -> Project Settings (Ctrl + Alt + Shift + S)

How do I check my Java version IntelliJ?

In the Project Structure dialog Ctrl+Alt+Shift+S , select SDKs. Select the necessary JDK version if you have several JDKs configured, and open the Documentation Path tab on the right.

How to resolve error Java invalid source release 11?

Error:java: invalid source release: 11 Follow the steps to resolve this error Click New button under Project SDK: Add the latest SDK and Click OK. After running You will see error is resolved.. If you don't SDK 12. Just add the latest one

Can I run Java program in IntelliJ IDEA?

You have setup Java 14 successfully in IntelliJ IDEA Please let me know if you have any other issue running Java program in your IntelliJ IDEA. We will try to provide answer at earliest convenience. If you liked this article, then please share it on social media. Still have any questions about an article, leave us a comment.

How to check if the project structure in IntelliJ is correct?

check if the project structure in IntelliJ is correct. File > Project Structure > Project Setting > Project -> SDK and Language level should match File > Project Structure > Project Setting > Modules -> Language Level should match with SDK

Why can't I start my project from intelij?

If you start your project from a main method directly invoked from Intelij then the missing dialog execution configurations may be the cause of the error. Always check the execution configurations to make sure the correct JRE folder is plugged in.


Video Answer


6 Answers

In intellij just set Gradle JVM to Java version 17.

"File -> Settings.. -> Build, Execution, Deployment -> Build Tools -> Gradle" there select your project and set Gradle JVM to your java 17.0.1

like image 165
Rakesh R Avatar answered Oct 19 '22 22:10

Rakesh R


Set Gradle JVM to target build jvm

File -> Settings.. ->enter image description here

like image 22
abhinavxeon Avatar answered Oct 19 '22 22:10

abhinavxeon


A picture is worth a thousand words!

Enter to preferences and change Gradle JVM.

enter image description here

like image 19
Jorge Tovar Avatar answered Oct 20 '22 00:10

Jorge Tovar


The message typically entails that your JAVA_HOME environment variable points to a different Java version.

Here are the steps to follow:

  • Close IntelliJ IDEA
  • Open a terminal window and check your JAVA_HOME variable value:
    • *nix system: echo $JAVA_HOME
    • Windows system: echo %JAVA_HOME%
  • The JAVA_HOME path should be pointing to a different path, then set it to the openjdk-17 path:
    • *nix system: export JAVA_HOME=/path/to/openjdk-17
    • Windows system: set JAVA_HOME=path\to\openjdk-17
  • Open your project again in IntelliJ IDEA
  • Make sure to set both source and target compatibility versions (not only the sourceCompatibility)

You should be able to build your project.

EDIT: Gradle Toolchain

You may need also to instruct Gradle to use a different JVM than the one it uses itself by setting the Java plugin toolchain to your target version:

// build.gradle
java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}
like image 18
tmarwen Avatar answered Oct 19 '22 22:10

tmarwen


Set JAVA_ HOME TO JDK 17 and check this by Opening cmd -> javac. This should return the current version of java set in your machine

like image 1
Virbhadra Kaulwar Avatar answered Oct 20 '22 00:10

Virbhadra Kaulwar


There could be many reasons due to which this error is thrown by intellij

  • Check your JAVA_HOME ->
echo $JAVA_HOME

if JAVA_HOME is not correct, update the JAVA_HOME environment variable.

  • check if the project structure in IntelliJ is correct.
File > Project Structure > Project Setting > Project -> SDK and Language level should match

File > Project Structure > Project Setting > Modules -> Language Level should match with SDK
  • Check and fix settings in preferences are correct
Preferences > Build, Execution and Deployment > Gradle > Gradle JVM should match with SDK (Preferences > Build, Execution and Deployment > maven if you're using maven)

Preferences > Build, Execution and Deployment > Compiler > Java Compiler > Project Bytecode version (this should match with your SDK as well)
like image 1
Sumit Jadiya Avatar answered Oct 19 '22 22:10

Sumit Jadiya