错误:java:javacTask:源版本 8 需要目标版本 1.8
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29888592/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error:java: javacTask: source release 8 requires target release 1.8
提问by Hobbyist
采纳答案by Weslor
- File > Settings > Build, Execution, Deployment > Compiler > Java Compiler
- Change Target bytecode versionto 1.8of the module that you are working for.
- 文件 > 设置 > 构建、执行、部署 > 编译器 > Java 编译器
- 将目标字节码版本更改为您正在使用的模块的1.8。
If you are using Maven
如果您使用的是 Maven
Add the compiler plugin to pom.xml
under the top-level project
node:
pom.xml
在顶级project
节点下添加编译器插件:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
(Hoisted from the comments.)
(从评论中提升。)
Note: If you don't mind reimporting your project, then the only thing you really need to do is change the pom and reimport the project, then IntelliJ will pick up the correct settings and you don't have to manually change them.
注意:如果您不介意重新导入您的项目,那么您唯一真正需要做的就是更改 pom 并重新导入项目,然后 IntelliJ 会选择正确的设置,您不必手动更改它们。
回答by Steve Chaloner
This looks like the kind of error that Maven generates when you don't have the compiler plugin configured correctly. Here's an example of a Java 8 compiler config.
这看起来像是当您没有正确配置编译器插件时 Maven 生成的那种错误。这是 Java 8 编译器配置的示例。
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- ... -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<!-- ... -->
</project>
回答by Gregory Mazur
回答by Lord Nighton
回答by snovelli
The quickest way I found:
我找到的最快方法:
- press:CTRL+ SHIFT+ A(For Mac ?+ SHIFT+ A)
- type:
java compiler
- press: ENTER
- 按:CTRL+ SHIFT+ A(对于 Mac ?+ SHIFT+ A)
- 类型:
java compiler
- 按: ENTER
In the Settings window, set the Target bytecode to 1.8
在设置窗口中,将目标字节码设置为1.8
(or 9for java9)
(或java9 为9)
回答by Sam Barnum
I fixed this by going to Project Structure-> Modules, find the module in question, click on Dependenciestab, change Module SDK
to Project SDK
.
我通过转到Project Structure-> Modules解决了这个问题,找到有问题的模块,单击Dependencies选项卡,更改Module SDK
为Project SDK
.
回答by user4884640
I fixed it by modify my POM file. Notice the last comment under the highest voted answer.
我通过修改我的 POM 文件来修复它。请注意最高投票答案下的最后一条评论。
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
The source must matches the target.
源必须与目标匹配。
回答by Cloud
In my case I fixed this issue by opening .iml fileof project (it is located in project root folder and have name same as the name of project) and changing line <orderEntry type="jdk" jdkName="1.7" jdkType="JavaSDK" />
to <orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
就我而言,我通过打开项目的.iml 文件(它位于项目根文件夹中,名称与项目名称相同)并将行更改<orderEntry type="jdk" jdkName="1.7" jdkType="JavaSDK" />
为<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
I had everything configured as in others answers here but by some reason Idea updated .iml file incorrectly.
我在此处的其他答案中配置了所有内容,但由于某种原因,Idea 错误地更新了 .iml 文件。
回答by Vishal
I fixed it just by changing target compile version to 1.8. Its in:
我只是通过将目标编译版本更改为 1.8 来修复它。在里面:
File >> Settings >> Build, Execution, Deployment >> Compiler >> Java Compiler
文件>>设置>>构建、执行、部署>>编译器>>Java编译器
回答by Marvin Richter
Many answers regarding Maven are right but you don't have to configure the plugin directly.
许多关于 Maven 的答案是正确的,但您不必直接配置插件。
Like described on the wiki pageof the Apache Maven Compiler Plugin you can just set the 2 properties used by the plugin.
就像在 Apache Maven Compiler Plugin的wiki 页面上描述的那样,您只需设置插件使用的 2 个属性。
<project>
[...]
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
[...]
</project>