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

前端 未结 16 891
旧时难觅i
旧时难觅i 2020-11-27 08:55

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 java         


        
相关标签:
16条回答
  • 2020-11-27 09:40

    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
    
    0 讨论(0)
  • 2020-11-27 09:40

    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 讨论(0)
  • 2020-11-27 09:42

    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.

    0 讨论(0)
  • 2020-11-27 09:44

    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.

    0 讨论(0)
  • 2020-11-27 09:45

    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.

    After running You will see error is resolved..

    0 讨论(0)
  • 2020-11-27 09:46

    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

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

    0 讨论(0)
提交回复
热议问题