2015-10-22 69 views
1

假设我有三个maven配置文件。如何在maven配置文件的一个子集中共享插件配置

  • local-dev
  • ci
  • prod

现在我有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有很多的配置,并自其在多个配置完全相同的,我很想把它定义一个地方,从需要在配置文件只是引用它。

回答

1

让我从the Maven forum举:

我的收获是,如果一个人只是轮廓跳跃作为解决每一个有条件的情况下,生成将在一个糟糕的恐怖片长出了第二头就像一个九头蛇,你会真的后悔。

重点是配置文件通常是正确使用Maven的权宜替代品。除非您知道自己想要什么,否则应始终将其视为“最后的手段”。

在我的情况下,[...]。配置文件对此很有帮助,但我可以确切地知道九头蛇头在哪里适合野兽,除非绝对必要,否则不打算对它们做更多的事情。

我已经使用我的配置文件的经验。我第二种观点。

从概念的角度来看,您有三个项目具有许多甚至大部分共同点。这是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 SetResourcesThe Build Element SetPOM参考对重定向所有的编译目录。

Maven include another pom for plugin configuration

唯一正确的答案是使用继承。

我第二,以及。

+0

所以这只是不可能与配置文件做到这一点? – duhseekoh

+0

@duhseekoh它不是,没有重复。但这不是由于配置文件的功能有限。这是由于POM的声明性质,其中正确的共享声明方式是通过继承(没有像'这样的POM元素)。另请参见[Maven包含另一个pom插件配置](http://stackoverflow.com/questions/5729437/maven-include-another-pom-for-plugin-configuration)。 –