Error: Java: invalid target release: 11 - IntelliJ IDEA

JavaIntellij IdeaJava 11

Java Problem Overview


I am trying to build an application which was built using java 8, now it's upgraded to java 11. I installed Java 11 using an oracle article in my windows machine and I use IntelliJ IDEA 2017 as my IDE.

I changed my system environment variables and set the

JAVA_HOME to C:\Program Files\Java\jdk-11.0.1

And added that to the Path variable.

C:\>java -version
java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode) 

When I build my application in IntelliJ, this is what I get:

Information:java: Errors occurred while compiling module 'test-domain_main'
Information: javac 1.8.0_171 was used to compile java sources
Information:1/10/2019 4:21 PM - Compilation completed with 1 error and 0 warnings in 1s 199ms
Error:java: invalid target release: 11

This is what I've tried so far:

  1. I changed .idea/compiler.xml target values from 8 to 11 but that didn't help. Also, verified the Target bytecode version in settings > Build, Execution, Deployment > Compiler > Java Compiler and all my modules are set to 11.

  2. Went to file > Project Structure > SDKs *(currently I have 1.7 and 1.7 listed)* > Add new SDK > JDK > After that, I selected C:\Program Files\Java\jdk-11.0.1 But it errors out with "The selected directory is not a valid home for JDK"

I am not sure if I installed the wrong JDK 11, because in my C:\Program Files\Java\, I see separate JDK and JRE folders for 1.7 and 1.8 but only JDK folder for 11.0.1

Or is it something else I need to change?

Java Solutions


Solution 1 - Java

I've got the same issue as stated by Gryu. Same Intellij 2018 3.3

I was able to start my project by setting (like stated by Grigoriy)

File->Project Structure->Modules ->> Language level to 8 ( my maven project was set to 1.8 java)

AND

File -> Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler -> 8 also there

I hope it would be useful

Solution 2 - Java

  • I've got the same info messages and error message today, but I have recently updated Idea -> 2018.3.3, built on January 9, 2019.

  • 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. I have 11 there.

  • Now I don't get these notifications and the error.

    It could be useful for someone like me, having the most recent Idea and getting the same error.

Solution 3 - Java

1 of the 2 methods will fix the problem:

Method 1 (recommended)

Specify the Java version in your build file.

E.g., For Gradle, go to build.gradle file and specify the source and target compatability like mentioned in the docs and click on the refresh button in the Gradle tool window.

For example, to set source and target compatability to Java version 17:

java {
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
}

Method 2

If building a project through a build system (Maven, Gradle etc..) via command-line works but IntelliJ show Invalid target release error, then do the following,

  1. Close IntelliJ

  2. Go to the directory of the project

  3. Delete the .idea/ directory

  4. Start IntelliJ with the project's directory

This will re-create the .idea/ directory and will no longer show the error.

NOTE: Any repository specific IntelliJ settings that you have added would be deleted when the .idea/ directory is deleted and they will be re-created with the defaults.

Solution 4 - Java

Below changes worked for me and hope the same works for you.

  1. Change the version of Java from 11 to 8 in pom.xml file
    1.8

  2. Go to, File -> Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler
    Here, in Module column you can see your project listed and in Target bytecode version column, Java version for the project is already specified(mostly 11), change it to 8

  3. Go to, File -> Project Structure -> Modules. Here, in Source tab, you can see Language level option, choose 8 - Lambdas, type annotations etc.. Finally, choose Apply and OK, you're good to go.

Solution 5 - Java

Please update to IntelliJ IDEA 2018.x to get Java 11 support. Your IntelliJ IDEA version was released before Java 11 and doesn't support this Java version.

Solution 6 - Java

January 6th, 2021

This is what worked for me.

Go to File -> Project Structure and select the "Dependencies" tab on the right panel of the window. Then change the "Module SDK" using the drop-down like this. Then apply changes.

image 1

Solution 7 - Java

There is also the possibility of Maven using a different version of JDK, in that case you can set Maven to use the project default JDK version.

enter image description here

Solution 8 - Java

In newer versions of Intellij, check that jdk 11 is correctly configured:

  1. Right click on your project then Open Module Settings. Check the settings listed below:
    • SDKs (Under Platform Settings) > Add the jdk 11 you want located on your computer.
    • Modules (Under Project Settings) > Set language level to jdk 11 for sources and dependencies.
    • Project (Under Project Settings) > Select jdk 11 as Project SDK. enter image description here enter image description here enter image description here
  2. Then File > Settings > Java Compiler. Check the following settings:
    • Use compiler: Javac
    • Project bytecode version: 11
    • Per-module bytecode version: the target bytecode version for all modules must be set to 11. enter image description here

Solution 9 - Java

Got this same error after updating my Idea and I resolved it as follows:

File >> Project Structure... >> Project

“Project language level:” was set to “11 - Local variable syntax for lambda parameters” so I changed it to “SDK default (8 - Lambdas, type annotations etc.)” then applied the change and the error was resolved.

Solution 10 - Java

I was recently facing the same problem. This Error was showing on my screen after running my project main file. Error:java: invalid source release: 11 Follow the steps to resolve this error

  1. File->Project Structure -> Project
  2. Click New button under Project SDK: Add the latest SDK and Click OK.

enter image description here

After running You will see error is resolved..

enter image description here

enter image description here

You can see it's work perfectly.. Please approach me If you find any problem

Solution 11 - Java

If you are in Springboot please check the java version in the pom.xml file

<properties>
   <java.version>11</java.version>
</properties>

If this version doesn't match with your default version(Java) of the computer, that error can be happen.

Solution 12 - Java

I had the issue because I'm currently upgrading my code base to JDK 11 and am switching between 8 and 11 in the branches. It seems IntelliJ doesn't like this.

Solution:

If you've selected the currect JDK in your project structure (Ctrl+Shift+Alt+S) and still get the error, invalidate your cache File > Invalidate Caches / Restart....

After restarting the IDE the error went away in my case.

Solution 13 - Java

I Could say I had similar issue. My case: I switched from new version to old version of the project in workspace, try to run single junit which require recompil, recompilation error was thrown with invalid target.

From Projects settings (F4) in IntelliJ everything was looking good and java was set to 1.7. But when I try recompile from IDE error was thrown because of wrong target level. After checking I found that in one of the iml file language was set to JDK_11. After manual change to JDK_1_7 everything back to normal.

Worth to also manual check lang level in *iml files created by IDE.

Solution 14 - Java

For me, I was having the same issue but it was with java v8, I am using a different version of java on my machine for my different projects. While importing one of my project I got the same problem. To check the configuration I checked all my SDK related settings whether it is in File->Project->Project Structure / Modules or in the Run/Debug configuration setting. Everything I set to java-8 but still I was getting the same issue. While checking all of the configuration files I found that compiler.xml in .idea is having an entry for the bytecodeTargetLevel which was set to 11. Here if I change it to 8 even though it shows the same compiler output and removing <bytecodeTargetLevel target="11" /> from compiler.xml resolve the issue.

Solution 15 - Java

My solution:

  1. Go to File > Settings > Build, Execution, Deployment > Build Tools > Gradle
  2. Select Gradle JVM: [SDK VERSION]
  3. Compile

enter image description here

Solution 16 - Java

My project module was set to 8 but the pom.xml was set to 11. When I changed from 8 to 11 in the module, it worked.

Solution 17 - Java

i also got same error , i just change the java version in pom.xml from 11 to 1.8 and it's work fine.

Solution 18 - Java

In your pom.xml file inside that write "8" instead write "11" ,and RECOMPILE your pom.xml file And tadaaaaaa it works !

Solution 19 - Java

I tried all the above and found this secret sauce

  1. make sure pom.xml specifies your desired jdk.
  2. make sure maven specifies your desired jdk.
  3. make sure Projects specifies your desired jdk.
  4. make sure Modules specifies your integer jdk AND Dependencies specifies your jdk. hth.

Solution 20 - Java

2021 Jan.12th

the whole point for me is to explicitly specify the version as java 11 in my pom.xml, and I solved the problem by taking the following steps.

  1. open terminal and input: java -version, then i got 1.8, and i went to .bash_profile to switch the java version to 11.2 as i have multiple java version installed. please remember "restart" your terminal and check your java version again to confirm switch is successful.

  2. Then i went to File -> Project Structure to make sure my IntelliJ using the same version as my env, which is 11.2.

  3. RESTART your Intellij, mvn clean install, solved, hope this could help someone that has same issue, thanks.

Solution 21 - Java

1. pom.xml (start with this important)
    - <java.version>1.8</java.version>
    * Enable auto import on pop up
    * Wait until it loads

2. Project Structure
    - Project
        - Project SDK - 1.8 
        - Project language Level - 8
    - Modules
        - Sources
            - Language level - 8
            - Dependencies - Project SDK 1.8

3. Delete idea folder
4. Close window
5. Reopen window (make sure it loads at bottom)

Solution 22 - Java

If your project is built using gradle, you should update:

File > Settings > Build, Execution, Deployment > Build Tools > Gradle

And update Gradle JVM with version 11.

Solution 23 - Java

Just had same error. Problem was that I had empty package-info.java file. As soon as I added package name inside it worked...

Solution 24 - Java

I also got a similar error but in my case it was Error:java: invalid source release: 11... So I just changed all the annotations of java 11 to java 8 and even if the annotation was java 8, I just leaved it like that. I hope it helps you to fix the issue.

Solution 25 - Java

I changed file -> project structure -> project settings -> modules In the source tab, I set the Language Level from : 14, or 11, to: "Project Default". This fixed my issue.

Solution 26 - Java

I added these two lines to build.gradle file

compileJava.options.fork = true
                                              
compileJava.options.forkOptions.executable = 'C:\\Program Files\\Java\\jdk-11.0.8'

and it works

I am using windows and my project based on gradle

my jdk path -> 'C:\Program Files\Java\jdk-11.0.8'

please provide your jdk path

Solution 27 - Java

Try this

<properties>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
</properties>

Solution 28 - Java

I tried all the solutions above

  • gradle jvm version , java compilter bytecode version, module language.

I set all the above to java 8 (or 1.8) as that is the library I have on my machine. It still did not work.

The issue was that the build.gradle file had

> sourceCompatibility = '11'

Changed this to 8 and it stopped throwing 'compile failed invalid release 11' error

solution reference: github forum

Solution 29 - Java

I got the same java 11 target error and my issue was maven-compiler-plugin outdated version. upgraded to lastest and everything worked

Solution 30 - Java

Setting the right path for Java home in gradle.properties solved the issue for me

gradle properties path : C:\Users<username>.gradle\gradle.properties

org.gradle.java.home=yourjdk11homepath
Example : org.gradle.java.home=C\:/Program Files/Java/jdk-11.0.8

Solution 31 - Java

If configuring the Project Properties never worked for you, you should also remember to change the SDK version for the maven or Gradle which could be pointing to the wrong path or the JDK version.

To do this:

  1. Click on File | Settings | Build, Execution, Deployment | Build Tools
  2. If maven, click maven then Runner, and set JRE to use project JDK.
  3. If Gradle, Click Gradle then set the Gradle JVM.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAMagicView Question on Stackoverflow
Solution 1 - JavaPaoloView Answer on Stackoverflow
Solution 2 - JavaGryuView Answer on Stackoverflow
Solution 3 - JavaneonidianView Answer on Stackoverflow
Solution 4 - JavaB SangappaView Answer on Stackoverflow
Solution 5 - JavaCrazyCoderView Answer on Stackoverflow
Solution 6 - JavaAlejandro ArevaloView Answer on Stackoverflow
Solution 7 - JavaamertkaraView Answer on Stackoverflow
Solution 8 - JavaPieberView Answer on Stackoverflow
Solution 9 - JavaAMS AbuView Answer on Stackoverflow
Solution 10 - JavaUzairView Answer on Stackoverflow
Solution 11 - JavaMafeiView Answer on Stackoverflow
Solution 12 - JavaYounes El OuartiView Answer on Stackoverflow
Solution 13 - JavatarkosView Answer on Stackoverflow
Solution 14 - JavaShriView Answer on Stackoverflow
Solution 15 - JavaEnrique AlcocerView Answer on Stackoverflow
Solution 16 - JavamarkthegreaView Answer on Stackoverflow
Solution 17 - JavaAmitPalView Answer on Stackoverflow
Solution 18 - Javauser14406165View Answer on Stackoverflow
Solution 19 - Javacp.View Answer on Stackoverflow
Solution 20 - JavaItwasJJsmileView Answer on Stackoverflow
Solution 21 - JavajoeabalaView Answer on Stackoverflow
Solution 22 - JavaJFLView Answer on Stackoverflow
Solution 23 - JavaBojan VukasovicView Answer on Stackoverflow
Solution 24 - Javamachete333View Answer on Stackoverflow
Solution 25 - JavaseekleView Answer on Stackoverflow
Solution 26 - Javaasifaftab87View Answer on Stackoverflow
Solution 27 - JavaAna Gabriela GuzmanView Answer on Stackoverflow
Solution 28 - JavaveritasView Answer on Stackoverflow
Solution 29 - JavaAdrianView Answer on Stackoverflow
Solution 30 - JavaJafar KaruthedathView Answer on Stackoverflow
Solution 31 - JavaDavid KariukiView Answer on Stackoverflow