gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-30 19:42:32 25 4
gpt4 key购买 nike

执行 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com