Maven2:如何在父子Pom之间共享插件配置? [英] maven2: how to share a plugin configuration between parent and children pom?

查看:105
本文介绍了Maven2:如何在父子Pom之间共享插件配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to reduce copy/pasting in our maven pom files.

我们有一个主pom,许多子项目pom是从该主继承的.

We have one master pom and many children projects pom inheriting from the master.

我想共享一个复杂的插件定义,如下所示:

I want to share a complex plugin definition looking like:

<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(位于或中)时,打包甚至不会开始.

When this plugin definition is in the project pom, packaging is well done.
When definition is moved to parent pom (in or in ), then the packaging is not even started.

是否可以共享插件配置?怎么样?

Is it possible to share a plugin configuration ? How ?

-在第一个答案后进行编辑---
我尝试了以下方法:
-将我的XL包装插件配置放入父pom
的元素中 -将此行添加到我的项目pom中的元素中:

-- Edit after first answers---
I have tried the following:
- put my XL packaging plugin config in the element of my parent pom
- add this lines in my project pom in the element:

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

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

but it is not working... What can be wrong with that ?

-最后编辑- 我想我出了什么问题:
插件重用声明应在配置文件构建中声明.
我是在始终启用的插件中完成的,现在可以正常工作了.

-- last edit -- I think I get what was the problem:
the plugin re-use declaration should be declared in a profile build.
I done that in an always enabled plugin and now it is working fine.

非常感谢.

推荐答案

您可以将父项的插件包装在<pluginManagement>标记中.

You could wrap the plugins of the parent in a <pluginManagement> tag.

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

当儿童插件在其build标签中声明该插件时,它们将继承配置.

Children plugins will then inherit the configurations when they declare the plugin in their build tag.

这篇关于Maven2:如何在父子Pom之间共享插件配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆