IDEA:javac:源版本 1.7 需要目标版本 1.7 [英] IDEA: javac: source release 1.7 requires target release 1.7
问题描述
在运行 JUnit 测试时,使用 IntelliJ IDEA,我得到
我该如何纠正?
- 使用 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屋!