IDEA:javac:源版本1.7需要目标版本1.7 [英] IDEA: javac: source release 1.7 requires target release 1.7
问题描述
当使用IntelliJ IDEA运行JUnit测试时,我得到
如何更正?
- 使用SDK 1.7
- 模块语言级别为1.7
Maven构建正常。 (这就是为什么我在IDEA配置问题中相信这一点)
很可能你在这里从Maven导入了错误的编译器选项:
还要检查屏幕截图中列出的项目和模块字节码(目标)版本设置。
源的其他地方语言级别已配置:
- 项目结构| 项目
- 项目结构|模块(检查每个模块)| 来源
Maven 默认语言级别 1.5 (5.0),您将在上面的屏幕截图中看到此版本为模块语言级别。
可以使用
When running a JUnit test, using IntelliJ IDEA, I get
How can I correct this?
- Using SDK 1.7
- Module language level is 1.7
Maven build works fine. (That's why I believe this in IDEA configuration issue)
Most likely you have incorrect compiler options imported from Maven here:
Also check project and module bytecode (target) version settings outlined on the screenshot.
Other places where the source language level is configured:
- Project Structure | Project
- Project Structure | Modules (check every module) | Sources
Maven default language level is 1.5 (5.0), you will see this version as the Module language level on the screenshot above.
This can be changed using maven-compiler-plugin configuration inside 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>
[...]
</project>
or
<project>
[...]
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
[...]
</project>
IntelliJ IDEA will respect this setting after you Reimport the Maven project in the Maven Projects tool window:
这篇关于IDEA:javac:源版本1.7需要目标版本1.7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!