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
.
In Modules -> Sources
I've set the Language level
to Project default (17 - Sealed types, always strict floating-point semantics)
.
In Modules -> Dependencies
I've set the Module SDK
to Project SDK openjdk-17
.
In Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler
I've set the Project bytecode version
to 17
.
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?
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.
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)
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.
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
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.
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
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.
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
Set Gradle JVM to target build jvm
File -> Settings.. ->
A picture is worth a thousand words!
Enter to preferences and change Gradle JVM.
The message typically entails that your JAVA_HOME environment variable points to a different Java version.
Here are the steps to follow:
echo $JAVA_HOME
echo %JAVA_HOME%
export JAVA_HOME=/path/to/openjdk-17
set JAVA_HOME=path\to\openjdk-17
sourceCompatibility
)You should be able to build your project.
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)
}
}
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
There could be many reasons due to which this error is thrown by intellij
echo $JAVA_HOME
if JAVA_HOME is not correct, update the JAVA_HOME environment variable.
File > Project Structure > Project Setting > Project -> SDK and Language level should match
File > Project Structure > Project Setting > Modules -> Language Level should match with SDK
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With