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

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

问题描述

现在,我正在自己编写一个小型 Java 应用程序,其中包含很少的 maven pom.xml 文件.我想让我所有的 maven 包都用 jdk 1.6 编译,如果没有在每个 POM 上手动设置它,我找不到一个好的方法 - 我厌倦了复制和粘贴

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>

在我生成的每个 pom.xml 文件中.

in every single pom.xml file I generate.

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

Is there a simpler way to resolve this issue?

推荐答案

创建具有编译器设置(以及任何其他默认设置)你想要的.您可以像对待任何其他项目一样对待它(发布它;将其部署到您的 Maven 存储库等).

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 文件的顶部放置一个 parent 声明:

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.

顺便说一句 - 在你的父 pom 文件中声明 dependenciesplugins 时要小心.通常你会喜欢dependencyManagementpluginManagement.请参阅 文档 了解更多详情.

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天全站免登陆