Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven2: how to share a plugin configuration between parent and children pom?

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

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>

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 ?

-- 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.

Thanks a lot.

like image 989
Guillaume Avatar asked Nov 10 '10 15:11

Guillaume


People also ask

Are plugins inherited from parent pom?

Plugins declared outside of <pluginManagement> are inherited by child POMs, by default. Their settings can be overridden by each child if desired.

What do child POMs inherit from the parent pom?

All Maven POMs inherit values from a parent POM. If a POM does not specify a direct parent using the parent element, that POM will inherit values from the Super POM. Project Inheritance shows the parent element of project-a which inherits the POM defined by the a-parent project.

How do I override plugin from parent pom?

Overriding configurations from a parent pom can be done by adding the combine. self="override" attribute to the element in your pom. It appears that for Maven2. 2.1 if you do this in a profile it doesn't merge with plugins defined in parent profiles but overrides them.

How do you provide relative path in pom xml?

Parent POM Relative Path By default, Maven looks for the parent POM first at project's root, then the local repository, and lastly in the remote repository. If parent POM file is not located in any other place, then you can use code tag. This relative path shall be relative to project root.


1 Answers

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

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

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

like image 169
John Vint Avatar answered Oct 13 '22 02:10

John Vint