java - 执行 maven 3 - 何时使用 maven enforcer 插件?什么时候使用 pom 先决条件元素?

标签 java maven

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

  • maven-enforcer-plugin 和
  • pom.xml <prerequisites>元素。

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

问题:什么类型的项目结构最适合maven-enforcer-plugin,什么类型的项目结构最适合pom先决条件。


Maven Enforcer 插件示例

<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 先决条件示例

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

最佳答案

先决条件已弃用,您应该使用 enforcer 插件。 MNG-5297请求文档更新以澄清这一点。

maven-enforcer-plugin 常见问题 explains the difference :

Why can't I just use the prerequisites tag in the 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.

此外,请注意 prerequisites do not work with Maven 3 .

关于java - 执行 maven 3 - 何时使用 maven enforcer 插件?什么时候使用 pom 先决条件元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18055009/

相关文章:

java - 使用maven将jar加载到项目中

java - 缩小操作栏后,抽屉导航切换不起作用

java - 无法在java中的tcpserver和tcpclient之间连续发送数据

java - com.ibm.wsspi.uow.UOWManager 的 NoClassDefFoundError

java - JFOREX SDK - 如何向 www 服务器 ssl 连接发送 HTTPS GET 请求

maven - 设置步骤和附件

tomcat - IntelliJ IDEA : Maven,项目编译部署

java - java类的字符串表达式

java - 从 JAX-WS Provider<SOAPMessage> 返回 SOAPFault

java - Apache Commons Net API 使用