执行maven 3 - 什么时候使用maven enforcer插件?什么时候使用pom先决条件元素? [英] enforcing maven 3 - when to use maven enforcer plugin? when to use pom prerequisites element?

查看:244
本文介绍了执行maven 3 - 什么时候使用maven enforcer插件?什么时候使用pom先决条件元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行maven 3的两种主要方法似乎是:

The two main approaches for enforcing maven 3 seem to be:


  • maven-enforcer-plugin和

  • pom.xml < prerequisites> element。

  • maven-enforcer-plugin, and
  • pom.xml <prerequisites> element.

最佳使用方法似乎取决于几个不同的因素。这个问题是为了帮助人们决定哪种方法对他们最有意义。

The best approach to uses seems to depend on a few different factors. This question is to help people decide which approach makes the most sense for them.

问题:什么类型的项目结构最适合maven-enforcer-plugin以及哪种类型的项目结构最适合于先决条件。

Question: What types of project structures are best suited to maven-enforcer-plugin and what types of project structure are best suited to pom prerequisites.

<build>
  <plugins>
    <plugin>
      <inherited>true</inherited>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-enforcer-plugin</artifactId>
      <version>1.3</version>
        <executions>
          <execution>
            <id>enforce-maven-3</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <requireMavenVersion>
                  <version>3.0.5</version>
                </requireMavenVersion>                
              </rules>
              <fail>true</fail>
            </configuration>
          </execution>
       </executions>
     </plugin>
  </plugins>
</build>



Maven POM先决条件示例



Maven POM Prerequisites Example

<project>
   ...
   <prerequisites>
       <maven>3.0.5</maven>
   </prerequisites>
   ...
</project>


推荐答案

不推荐使用先决条件,您应该使用enforcer插件。 MNG-5297 要求提供文档更新以澄清此问题。

Prerequisites are deprecated, and you should use the enforcer plugin. MNG-5297 requests a documentation update to clarify this.

maven-enforcer-plugin 常见问题解释差异


为什么我不能只使用pom中的先决条件标记?

Why can't I just use the prerequisites tag in the pom?

先决条件标记旨在供插件等工具使用。它适用于常规项目,但不会遗传给他们的孩子。如果在父反应堆中设置,则Maven将进行检查。 但是,如果构建其中一个子项,则不会执行检查。 enforcer插件旨在允许从单个super-pom集中控制构建环境,并允许更大的灵活性支持范围的版本规范。

The prerequisites tag was designed to be used by tools like plugins. It will work for regular projects, but it isn't inherited to their children. If it is set in a parent reactor, then Maven will do the check. However if one of the children are built, the check is not performed. The enforcer plugin is designed to allow centralized control over the build environment from a single "super-pom", and to allow greater flexibility in version specification by supporting ranges.

此外,请注意先决条件不适用于Maven 3

这篇关于执行maven 3 - 什么时候使用maven enforcer插件?什么时候使用pom先决条件元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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