371

Im trying to compile some code in I'm using Intellij Ultimate 13.1.4, but I get the following error and I have no idea what it means:

Information:Using javac 1.7.0_55 to compile java sources
Information:java: Errors occurred while compiling module 'Example'
Information:Compilation completed with 1 error and 0 warnings in 3 sec
Information:1 error
Information:0 warnings
Error:java: invalid source release: 8

My guess is that its something related to Java 8 vs Java 7, but I have no idea what specifically. I've tried to Google around for this message, but they either talk about javac or target release, so it doesn't exactly seem to apply.

David says Reinstate Monica
  • 16,634
  • 19
  • 69
  • 108
  • 2
    What version of Java is installed? What JRE/JDK did you point intellij to, in the IDE settings? – nanofarad Sep 16 '14 at 20:41
  • 2
    Probably project settings. Check the JDK you're pointing to and the language level you asked for. – duffymo Sep 16 '14 at 20:43
  • 1
    @duffymo you were right, it was pointing to 8. I didnt realize that was a setting. – David says Reinstate Monica Sep 16 '14 at 21:02
  • possible duplicate of [Unable to compile using Java 1.7 in Jetbrains Intellij after moving from 1.6 to 1.7 (maven based project)](http://stackoverflow.com/questions/12745510/unable-to-compile-using-java-1-7-in-jetbrains-intellij-after-moving-from-1-6-to) – Victor Sergienko Dec 28 '14 at 10:38

16 Answers16

862

I had the same issue when "downgrading" a project from Java 8 to Java 6. The reason was that it was not changed at all places in IntelliJ.

In IntelliJ 13.1.4 I had to change Java and SDK version on the following places not to get this error:

  • File -> Project Structure -> Project Settings
  • File -> Project Structure -> Module Settings -> Tab: Sources: Language Level
  • File -> Project Structure -> Module Settings -> Tab: Dependencies: Module SDK
  • File -> Settings -> Compiler -> Java Compiler -> Target bytecode version

screen shot of File > Project Structure > Project

screen shot of File > Project Structure > Modules > Sources

screen shot of File > Project Structure > Modules > Dependencies

screen shot of File > Settings/Preferences > Compiler > Java Compiler

The last bullet was the one that was not updated in my case. Once I changed this, the error disappeared.

Basil Bourque
  • 218,480
  • 72
  • 657
  • 915
Andreas Lundgren
  • 10,546
  • 3
  • 18
  • 31
  • 34
    the one killing me was this one: `File -> Settings -> Compiler -> Java Compiler -> Target bytecode version` . Thanks. – bitoiu Mar 03 '15 at 11:05
  • 20
    I was running into this issue as well, but none of the above worked. I had to do `IntelliJ IDEA -> Preferences... -> Build, Execution, Deployment -> Build Tools -> Gradle -> Gradle JVM`, in case anyone is running into this issue whilst using Gradle. – Emil Aug 19 '15 at 01:14
  • 2
    Source: Language Level change to 7 - Diamonds, ARM, multi-catch etc. for IDEA 15 – Mia Dec 17 '15 at 03:09
  • 4
    This should be the accepted answer. As a small heads-up, in IntelliJ IDEA 15, point 4 has moved to `Preferences -> Build, Execution, Deployment -> Compiler -> Java Compiler`. – iusting Jan 27 '17 at 12:48
  • There is also a JRE selection in some run/debug configurations. For example, Tomcat run/debug configs have a "JRE" selector that can cause this error. – jordanpg Mar 27 '17 at 16:10
  • Also don't forget the JDK IDEA is running under as well as the JDK used by the underlying OS (for example if you use jenv). See: https://intellij-support.jetbrains.com/hc/en-us/articles/206544879-Selecting-the-JDK-version-the-IDE-will-run-under – jordanpg Mar 27 '17 at 20:14
  • I faced the same error and the solution mentioned worked out perfectly fine, the thing is one needs to know what language level was the project compiled in and change the project to use that language level. – AnkitSablok Jul 27 '17 at 22:15
  • This really helped. I had changed the version from all the places except Project SDK. – Amar Gajbhiye Dec 05 '18 at 09:06
  • I tried all of this in 2018.3.6 and nothing worked - I blew away the .idea directory and re-initialised the project - then it worked. – Michael Coxon May 06 '19 at 21:51
  • One more thing i did apart from the mentioned step, edit configuration -> application -> select the your application and check the JRE drop-down and select which you wanted to have in case it was jdk11. – Indrajeet Gour Mar 05 '20 at 19:37
  • what a legend tysm –  Apr 01 '21 at 22:58
18

Check your pom.xml first (if you have one)
Check your module's JDK dependancy. Make sure that it is 1.8
To do this,go to Project Structure -> SDK's
Add the path to where you have stored 1.8 (jdk1.8.0_45.jdk in my case)
Apply the changes
Now, go to Project Structure ->Modules
Change the Module SDK to 1.8
Apply the changes

Voila! You're done

Newd
  • 2,148
  • 2
  • 15
  • 31
Yash Bajaj
  • 189
  • 1
  • 4
6

Change in pom.xml 1.6 to 1.8

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
</plugin>
Haroldo Gondim
  • 6,811
  • 9
  • 40
  • 58
Aziz Mamoyan
  • 61
  • 1
  • 3
6

For Gradle users having this issues, if nothing above helps this is what solved my problem - apply this declarations in your build.gradle files:

targetCompatibility = 1.6 //or 1.7;1.8 and so on
sourceCompatibility = 1.6 //or 1.7;1.8 and so on

Problem solved!

Java_Waldi
  • 876
  • 2
  • 12
  • 28
5

It can be simply overcome by setting on Project Structure. You just need to select the right path for related version of JDK. Select new on dependencies tab, and choose the path. It's done!

enter image description here

snr
  • 13,515
  • 2
  • 48
  • 77
4

If you are using Gradle as a build tool and you get this error when executing a Gradle task i.e TomcatRun take a look to my other answer to the same question

javac: invalid target release: 1.8

Community
  • 1
  • 1
juliangonzalez
  • 3,616
  • 28
  • 43
2

Andreas Lundgren's answer worked and I was able to compile and run my app.

However, when I tried to run the project's associated JUnit tests I received the same error. Running

gradle -version

from Windows command prompt showed that gradle was still picking up the incorrect jdk. To fix it I had to set the JAVA_HOME environment variable to point to the correct jdk and restart IntelliJ.

jilbot
  • 125
  • 3
  • 8
1

I checked all above said project version, module version, project bytecode version, target bytecode version settings in IntelliJ Idea, but all were the same as I scratched.

I face this error Error:java: invalid source release: 1.8 in IntelliJ Idea 2017.2.6 because I upgraded the dependency version Maven pom file, which(dependency) were supposed to build for JDK 1.8 application and I were building my application on and with maven compiler source and target JDK 1.7.

Hence I again downgrade the dependency version to earlier one in Maven pom, and the error gone after project Rebuild Module 'xyz_project'.

ArifMustafa
  • 3,691
  • 4
  • 34
  • 44
0

For Grails users, apply these declarations in your BuildConfig.groovy file:

grails.project.target.level = 1.6 //or 1.7;1.8 and so on
grails.project.source.level = 1.6 //or 1.7;1.8 and so on
B5A7
  • 773
  • 10
  • 19
0

You need to click to the project Open Module Settings and change the path of your JDK, if in the file POM you use jdk 1.8, configure jdk 1.8 with correct path.

0

I add one more path unmentioned in this answer https://stackoverflow.com/a/26009627/4609353

but very important is Edit Configurations

one more path

Oleg Ushakov
  • 388
  • 3
  • 15
0

I tried out all the steps mentioned in here https://stackoverflow.com/a/26009627/2058104, but the 4th point has now changed. You need to go to Preferences -> Build, Execution, Deployment -> Compiler -> Java Compiler

In there, as shown in below figure, you need to change the "Target bytecode version". Although, I changed it to 8 (since I needed to downgrade to Java 8), it was giving the same error, over and over. Therefore, try to remove the existing entry (in this table) and add it again. This worked for me.

enter image description here

On the other hand, clean the project and try to run again.

cresclux
  • 76
  • 3
0

I had the same issue the solution for me was to change my java version in the pom.xml file.

I changed it from 11 to 8. enter image description here

Derek MC
  • 356
  • 2
  • 4
  • 22
0

Lots of good answers. For those using the (almost) latest version of Intellij, at the time of writing, what can be said, is that the project JDK can be at a higher level, than that of the module. In fact without it, Maven will have to be rolled back to an older version. Therefore with the following version of Intellij: enter image description here

One should not change the project level JDK and therefore be able to leverage the Maven or Gradle settings when building, but when running Maven or running Gradle using a more modern version of the JDK. If you lower your project level JDK from say JKD8 to JDK6, Maven or Gradle will not run.

Keeping your module at a lower level JDK-wise will enable you to build it to that version, if you use the Module rebuild or build options; using the menu options for rebuilding the project will complain wit "Invalid source release:8...".

Beezer
  • 937
  • 9
  • 14
0

As Andreas mentioned all about:

Error:java: invalid source release: 8 in IntelliJ
Error:java: invalid source release: 13 in IntelliJ
Error:java: invalid source release: 14 in IntelliJ...

OR whatever version you are using in Java...

The problem will exist if you do not have it matching inside the below code:

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

This 1.8 in my case, must be matching on your device through MAVEN project library, settings, preferences, project setting and SDK.

Daniel Manta
  • 5,682
  • 13
  • 35
  • 38
0

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

Uzair
  • 159
  • 1
  • 7