gpt4 book ai didi

maven - 如何在 Maven 配置文件的子集之间共享插件配置

转载 作者:行者123 更新时间:2023-12-02 04:16:36 24 4
gpt4 key购买 nike

假设我有三个 Maven 配置文件。

  • 本地开发
  • ci
  • 产品

现在我有 ciprod 使用完全相同的插件配置。我根本不想 local-dev 使用它。所以它看起来像这样。

<profile>
<id>local-dev</id>
</profile>
<profile>
<id>ci</id>
<build>
<plugins>
<plugin>
<artifactId>A-PLUGIN</artifactId>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>prod</id>
<build>
<plugins>
<plugin>
<artifactId>A-PLUGIN</artifactId>
</plugin>
</plugins>
</build>
</profile>

事实证明 A-PLUGIN 有很多配置,并且由于它在多个配置文件中完全相同,我喜欢将它定义在一个地方并从它需要的配置文件中引用它.

最佳答案

让我引用自the Maven forum :

My takeaway was that if one just jumps on profiles as the solution to every conditional situation, the build will grow a second head like a hydra in a bad horror flick and you'll really regret it.

The point is that profiles are often an expedient substitute for using Maven correctly. They should always be considered "last resort" unless you know what you are getting yourself into.

In my situation, [...]. Profiles work great for that, but I can see exactly where the hydra head fits on the beast now and don't intend on doing anything more with them unless absolutely necessary.

我已经通过配置文件获得了经验。我支持这个观点。

从概念的角度来看,您有三个项目,它们有许多甚至大部分的共同点。这就是 Maven 的 POM 层次结构及其继承发挥作用的地方:

main-parent
+- pom.xml ... containing declarations common to dev, ci & prod
+- dev
| +- pom.xml ... almost empty since everything's inherited from parent
| +- ... sources, resources, etc. ...
+- ci-prod-parent
+- pom.xml ... containing A-PLUGIN and other declarations specific to ci & prod
+- ci
| +- pom.xml ... almost empty since everything's inherited from parent(s)
| redirecting <build>/<[[test]source|resource>/]|
| [[test]output|testresource>/]directory> to ../../dev/...
+- prod
+- pom.xml ... almost empty since everything's inherited from parent(s)
redirecting <build>/<[[test]source|resource>/]|
[[test]output|testresource>/]directory> to ../../dev/...

参见 The BaseBuild Element Set , ResourcesThe Build Element SetPOM Reference 中找到所有要重定向的构建目录。

另见 Maven include another pom for plugin configuration :

The only correct answer is to use inheritance.

我也支持。

关于maven - 如何在 Maven 配置文件的子集之间共享插件配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33292068/

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