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

血红的双手。 提交于 2019-11-26 08:40:37

问题


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.


回答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

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




回答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




回答3:


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!




回答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




回答5:


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>



回答6:


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!




回答7:


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.




回答8:


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'.




回答9:


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



回答10:


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.




回答11:


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

but very important is Edit Configurations



来源:https://stackoverflow.com/questions/25878045/errorjava-invalid-source-release-8-in-intellij-what-does-it-mean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!