在Eclipse中为Maven项目设置默认的Java合规性级别 [英] Set default java compliance level for Maven projects in Eclipse
问题描述
Maven的默认合规级别是1.5,每次我在Eclipse中更新maven项目时,它都会将合规级别从1.6恢复到1.5,这对我来说真的很烦人。
The default compliance level for Maven is 1.5 and every time that I update a maven project in Eclipse it sets back the compliance level from 1.6 to 1.5 which is really annoying for me.
我知道我可以在POM文件中将目标设置为1.6,但问题是我不能在父POM中设置它并期望孩子继承它。所以我必须为每个Maven模块做这件事。我怎么能在我的Maven项目或整个eclipse中设置一次生命周期而不修改每个Maven模块!?
I know that I can set the target to 1.6 in the POM file but the problem is that I cannot set this in the parent POM and expect the children to inherit it. So I have to do it for every single Maven module. How can I set it in my Maven project or in the whole eclipse once for a "lifetime" without modifying every single Maven module!?
推荐答案
我知道我可以在pom文件中将目标设置为1.6,但问题是我不能在父pom中设置它并期望孩子继承它。
I know that I can set the target to 1.6 in pom file but the problem is that I cannot set this in the parent pom and expect the children to inherit it.
设置< source>
和< ;目标>
父pom中的版本确实有效。
Setting the <source>
and <target>
version in the parent pom does work.
例如,在我的父pom中,我有:
For example, in my parent pom, I have:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
如果您遇到问题,可能需要检查:
If you are having problems, you might want to check that:
- 子项指定父项的正确版本;
- 父pom指定
源
和目标
值; - 您已经运行
mvn install
在父母身上;和 -
mvn help:有效-pom
在子项目中显示预期的源/目标值。
- the child specifies the correct version of the parent;
- the parent pom specifies both
source
andtarget
values; - you have run
mvn install
on the parent; and mvn help:effective-pom
on the child project shows the expected source/target values.
修改poms后,您可能需要选择两个项目并使用 Maven-> Update Project 。
After modifying the poms, you may need to select both projects and use Maven->Update Project.
这篇关于在Eclipse中为Maven项目设置默认的Java合规性级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!