【问题标题】:maven2: how to share a plugin configuration between parent and children pom?maven2:如何在父子pom之间共享插件配置?
【发布时间】:2011-05-07 22:39:17
【问题描述】:

我正在尝试减少 maven pom 文件中的复制/粘贴。

我们有一个 master pom 和许多从 master 继承的子项目 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>

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

-- 最后一次编辑-- 我想我明白了问题所在:
插件重用声明应在配置文件构建中声明。
我在一个始终启用的插件中做到了这一点,现在它工作正常。

非常感谢。

【问题讨论】:

    标签: maven-2 plugins


    【解决方案1】:

    您可以将父级的插件包装在 &lt;pluginManagement&gt; 标记中。

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

    子插件在它们的构建标签中声明插件时将继承配置。

    【讨论】:

    • 我已经尝试过了,但它不起作用。我已经更新了关于您的回答的问题。
    • 运行 help:effective-pom 看看插件配置是什么样子的。你肯定在使用 pluginManagenement 吗?
    • 使用插件的构建已在配置文件中声明。所以插件配置也应该在配置文件中声明...感谢您的帮助。
    【解决方案2】:

    您是否尝试过使用 Maven 的 plugin management 功能?它将允许您将该配置信息从父 pom.xml 推送到子 pom.xml 文件:

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

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

    【讨论】:

      猜你喜欢
      • 2010-12-04
      • 1970-01-01
      • 2015-04-15
      • 1970-01-01
      • 2016-01-19
      • 1970-01-01
      • 1970-01-01
      • 2011-10-26
      • 2017-08-08
      相关资源
      最近更新 更多