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:
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.
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?
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.
I've got the same issue like stated by Grigoriy Yuschenko.
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
If building a project through a build system (Maven, Gradle etc..) works but IntelliJ show Invalid target release
error, then do the following,
Close IntelliJ
Go to the directory of the project
Delete the .idea/ directory
Start IntelliJ with the project's directory
This will re-create the .idea/ directory and will no longer show the error
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.
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.
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.
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.
Just had same error. Problem was that I had empty package-info.java file
. As soon as I added package name inside it worked...