gpt4 book ai didi

java - IntelliJ IDEA 中 maven 项目的不同源和 testSource JDK

转载 作者:搜寻专家 更新时间:2023-11-01 03:21:37 24 4
gpt4 key购买 nike

<分区>

我在 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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com