作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
<分区>
我在 IDEA 中导入了一个 maven 项目。有一个子模块对常规源和测试源使用不同版本的 java - 它对常规源使用 java 1.4,对测试源使用 java 7,如下所示:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.4</source>
<target>1.4</target>
<testSource>1.7</testSource>
<testTarget>1.7</testTarget>
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
项目在maven中编译正常,在IDEA中编译失败。当我打开 Project Structure -> module settings 时,我看到导入的模块的语言级别为 1.4。因此,测试类的编译失败,因为它们使用了 1.4 中不可用的功能。
作为解决方法,我手动更改 pom.xml 中的 java 版本。有没有办法不用修改maven配置就可以做到?
编辑:按照评论中的建议,我在IDEA中的Project structure中手动更改了设置,但是在编译项目时出现以下错误:
Information:3/20/2015 5:29 PM - Compilation completed with 1 error and 0 warnings in 5 sec
Error:java: javacTask: source release 1.7 requires target release 1.7
这个问题在这里已经有了答案: Handle different language and target levels for sources and tests with IntelliJ IDEA
我是一名优秀的程序员,十分优秀!