Home > front end >  Avoid inheritance of plugins configurations by external modules
Avoid inheritance of plugins configurations by external modules

Time:07-05

Suppose I have the three following maven modules :

  • parent
  • heir (submodule of parent, parent is its parent)
  • extern (other project, parent is its parent)

I would like to configure plugins only for parent and its submodules (parent and heir in my example) without any side effect for external projects (extern in this case).

parent defines a plugin in pluginManagement, for example :

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
        <execution>
            <id>hello, heir</id>
            <phase>compile</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>echo</executable>
                <arguments>
                    <argument>Hello, heir!</argument>
                </arguments>
            </configuration>
        </execution>
    </executions>
</plugin>

Unfortunately, this plugin configuration will have a side effect on extern. See, if extern defines the following, the above configuration will apply to him :

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>3.0.0</version>
    ...
</plugin>

Now, how can change my project structure or pom configuration so that :

  1. I can build my whole project from a single command on one pom
  2. I can deploy my whole project from a single command on one pom
  3. I can define plugins for internal use only (parent pom and its submodules) / An external project will not inherit from these plugins
  4. Said plugins are still inherited from internal plugins

?

CodePudding user response:

You need to change the hierarchy to

  • external-parent
  • parent
  • submodules
  • Related