Error:java: invalid source release: 8 in Intellij. What does it mean?

315,214

Solution 1

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.

Solution 2

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

Solution 3

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>

Solution 4

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!

Solution 5

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

Share:
315,214
David says Reinstate Monica
Author by

David says Reinstate Monica

https://meta.stackexchange.com/questions/333965/firing-mods-and-forced-relicensing-is-stack-exchange-still-interested-in-cooper?noredirect=1&amp;lq=1 https://meta.stackexchange.com/questions/336024/how-can-we-put-pressure-on-stack-exchange-inc-without-damaging-the-community#comment1110223_336024 https://meta.stackexchange.com/questions/336526/stack-overflow-is-doing-me-ongoing-harm-its-time-to-fix-it Please help in saving StackOverflow!

Updated on January 21, 2022

Comments

  • David says Reinstate Monica
    David says Reinstate Monica over 2 years

    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.

  • bitoiu
    bitoiu about 9 years
    the one killing me was this one: File -> Settings -> Compiler -> Java Compiler -> Target bytecode version . Thanks.
  • Emil
    Emil over 8 years
    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.
  • chazzlabs
    chazzlabs over 8 years
    Thanks! This resolved my issue after the above answers didn't.
  • Mia
    Mia over 8 years
    Source: Language Level change to 7 - Diamonds, ARM, multi-catch etc. for IDEA 15
  • iusting
    iusting over 7 years
    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.
  • jordanpg
    jordanpg about 7 years
    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
    jordanpg about 7 years
    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: intellij-support.jetbrains.com/hc/en-us/articles/…
  • AnkitSablok
    AnkitSablok almost 7 years
    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.
  • Amar Gajbhiye
    Amar Gajbhiye over 5 years
    This really helped. I had changed the version from all the places except Project SDK.
  • Michael Coxon
    Michael Coxon about 5 years
    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.
  • Indrajeet Gour
    Indrajeet Gour about 4 years
    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.
  • Uzair
    Uzair over 3 years
    If you don't SDK 12. Just add the latest one
  • Admin
    Admin about 3 years
    what a legend tysm
  • payne
    payne over 2 years
    Ended up having to modify the value of the cloned repo in its root build.gradle (the sourceCompatibility value).