2010-11-10 67 views
10

我試圖在我們的maven pom文件中減少複製/粘貼。maven2:如何在家長和孩子pom之間共享一個插件配置?

我們有一個主POM和許多孩子項目POM從主繼承。

我想分享一個複雜的插件定義看起來像:

<plugins> 
    ... 
    <plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>appassembler-maven-plugin</artifactId> 
     <configuration> 
      <!-- many xml lines here --> 
     </configuration> 

     <executions> 
      <execution> 
       <phase>package</phase> 
       <goals> 
        <goal>assemble</goal> 
        <goal>generate-daemons</goal> 
        <goal>create-repository</goal> 
       </goals> 
      </execution> 
     </executions> 

     <dependencies> 
      <dependency> 
       <groupId>org.codehaus.mojo.appassembler</groupId> 
       <artifactId>appassembler-booter</artifactId> 
       <version>1.0</version> 
      </dependency> 
     </dependencies> 
    </plugin> 
    ... 
</plugins> 

當這個插件的定義是在項目POM,包裝做得不錯。
當定義移動到父pom(in或in)時,那麼包裝甚至不會啓動。

是否可以共享插件配置?怎麼樣 ?

- 第一個答案後編輯---
我曾嘗試以下:
- 把我的XL包裝插件的配置在我父POM的元素
- 中的元素在我的項目POM添加此行:

<plugins> 
... 
    <plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>appassembler-maven-plugin</artifactId> 
    </plugin> 
... 
</plugins> 

,但它是不工作... 什麼可以錯嗎?

- 上次編輯 - 我想我得到了什麼問題:
插件重用聲明應該在配置文件構建中聲明。
我在一個始終啓用的插件中做到了這一點,現在它工作正常。

非常感謝。

回答

13

您可以將父項的插件包裝在<pluginManagement>標記中。

<build> 
     <pluginManagement> 
      <plugins> 
       <plugin> ... </plugin> 
      </plugins> 
     </pluginManagement> 
    </build> 

當他們在構建標記中聲明插件時,子插件將繼承配置。

+0

我試過這個,但它不工作。我已經更新了關於您的答案的問題。 – Guillaume 2010-11-10 15:21:20

+0

運行help:effective-pom並查看插件配置的外觀。你肯定使用插件管理?使用該插件構建的 – 2010-11-10 15:23:19

+0

已在配置文件中聲明。所以插件配置應該已在配置文件中聲明...感謝您的幫助。 – Guillaume 2010-11-12 10:19:31

2

您是否嘗試過使用Maven的plugin management功能?這將允許您向下推,該配置信息給孩子的pom.xml文件從父pom.xml中:

<build> 
     <pluginManagement> 
      <plugins> 
       <plugin>your_plugin</plugin> 
      </plugins> 
     </pluginManagement> 
    </build> 

現在,並不是所有的插件,以及完成那些從org.apache.maven .plugins組。可能需要將您的配置部分移到執行元素之間。