开发者

Running a maven plugin only in the parent

开发者 https://www.devze.com 2023-03-06 21:34 出处:网络
I\'ve created a maven plugin to start, clean and stop a database. My project consists of a pom file with 4 modules:

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>infrastr开发者_如何学运维ucture</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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号