问题 maven2:如何在父子pom之间共享一个插件配置?


我正在尝试减少我们的maven 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>

但它不起作用...... 这可能有什么问题?

- 最后编辑 - 我想我得到了什么问题:
应该在配置文件构建中声明插件重用声明。
我在一个始终启用的插件中完成了它,现在它工作正常。

非常感谢。


7048
2017-11-10 15:00


起源



答案:


您可以将父项的插件包装在一个 <pluginManagement> 标签。

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

然后,子插件在他们的构建标记中声明插件时将继承配置。


14
2017-11-10 15:04



我试过这个,但它没有用。我已经更新了有关您答案的问题。 - Guillaume
运行help:effective-pom并查看插件配置的外观。你肯定在使用pluginManagenement吗? - John Vint
使用插件的构建在配置文件中声明。所以插件配置也应该在个人资料中声明...感谢您的帮助。 - Guillaume


答案:


您可以将父项的插件包装在一个 <pluginManagement> 标签。

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

然后,子插件在他们的构建标记中声明插件时将继承配置。


14
2017-11-10 15:04



我试过这个,但它没有用。我已经更新了有关您答案的问题。 - Guillaume
运行help:effective-pom并查看插件配置的外观。你肯定在使用pluginManagenement吗? - John Vint
使用插件的构建在配置文件中声明。所以插件配置也应该在个人资料中声明...感谢您的帮助。 - Guillaume


你试过用过吗? 插件管理 Maven的特点?它允许您将该配置信息向下推送到父pom.xml中的子pom.xml文件:

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

现在,并非所有插件都与org.apache.maven.plugins组中的插件一样好。可能需要在执行元素之间移动配置部分。


2
2017-11-10 15:06