Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a maven plugin only in the parent

I've created a maven plugin to start, clean and stop a database. My project consists of a pom file with 4 modules:

<modules>
    <module>infrastructure</module>
    <module>domain</module>
    <module>application</module>
    <module>presentation</module>
</modules>

The plugin is only specified in this pom, and not in the pom of the modules. When I go to cmd to start a database with:

mvn hsqldb:startdb

Maven tries to create a database for every pom file. It actually starts 5 databases (one for the parent pom, and one for each module). However, I only want one (from the parent pom). In my parent pom file, the plugin is declared like this:

<plugin>
    <groupId>sample.plugin</groupId>
    <artifactId>hsqldb-maven-plugin</artifactId>
    <version>1.0-SNAPSHOT</version>
    <inherited>false</inherited>
    <dependencies>
        <dependency>
            ...
        </dependency>
    </dependencies>
    <executions>
        ...
    </executions>
    <configuration>
        ...
    </configuration>
</plugin>

Any solutions for my problem?

Kind regards,

Walle

like image 235
Walle Avatar asked May 18 '11 07:05

Walle


People also ask

What is the use of parent in Maven?

A parent pom. xml file (or super POM) in Maven is used to structure the project in order to avoid redundancies and duplicate configurations by using an inheritance between different pom. xml files. If any dependency or properties are configured in both - parent and child - pom.

What is the difference between plugin and pluginManagement tags?

pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one.

Are plugins inherited from parent pom?

1. Overview. Maven allows us to build a project using the concept of inheritance. When a parent POM defines a plugin, all of the child modules inherit it.

How do you override a parent POM plugin?

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.


1 Answers

Two ways:

  • On the command line, do mvn hsqldb:startdb -N

    -N,--non-recursive
    Do not recurse into sub-projects

    (Source) or

  • annotate your plugin with @aggregator

    Flags this Mojo to run it in a multi module way, i.e. aggregate the build with the set of projects listed as modules.

    (Source)

    While it's not explicitly said, this means that your plugin is put in charge of building the child modules, i.e. the child modules won't be built automatically.

Either way, it will only build the top project and not descend into modules. There is no way I know of that you can configure this in a pom.

like image 122
Sean Patrick Floyd Avatar answered Sep 17 '22 11:09

Sean Patrick Floyd