默认maven编译器设置 [英] default maven compiler setting

查看:117
本文介绍了默认maven编译器设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我正在写一个小的java应用程序,我自己,几个maven pom.xml文件。我想让所有我的maven包编译与jdk 1.6,我找不到一个好的方法来做,而无需手动设置它在每个单个POMs - 我生病的复制和粘贴

Right now, I'm writing a small java application by my own, with few maven pom.xml files. I want to make all my maven packages to compile with jdk 1.6, and I can't find a good way to do it without manually setting it on every single POMs - I'm sick of copy-and-pasting

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
 <source>1.6</source>
 <target>1.6</target>
</configuration>

文件我生成。

有更简单的方法来解决这个问题吗?

Is there a simpler way to resolve this issue?

推荐答案

创建具有所需编译器设置(以及任何其他默认设置)的pom-only(< packaging> pom< / package> )。

Create a pom-only (<packaging>pom</packaging>) project that has the compiler settings (and any other default settings) you want. You give treat it like any other project (release it; deploy it to your Maven repo, etc.).

放置一个您的pom文件顶部的c $ c>声明:

Put a parent declaration at the top of your pom files:

<parent>
  <groupId><!-- parent's group id --></groupId>
  <artifactId><!-- parent's artifact id --></artifactId>
  <version><!-- parent's version --></version>
</parent>

如果你想设置的都是编译器设置,但是如果你发现自己在整个项目中以同样的方式配置了很多插件,报表和依赖项,你可以创建一个父项来对它们进行规则。

It doesn't help much if all you want to set is compiler settings. But if you find yourself configuring lots of plugins, reports and dependencies in the same way across project, you can create one parent to rule them all.

BTW - 在父pom文件中声明 dependencies plugins 。通常,您会希望 dependencyManagement pluginManagement 。请参见 文档了解详情。

BTW - be careful about declaring dependencies and plugins in your parent pom file. Usually you'll want to favor dependencyManagement and pluginManagement. See the documentation for more details.

这篇关于默认maven编译器设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆