conedmiro
conedmiro

Reputation: 103

Is there a way to share a common configuration [with a config file / etc] for a maven plugin between modules?

I've got a multi-module maven project that is outputting 2 different versions of an RPM. They are very similar except a few files, and the de.dentrassi.maven RPM plugin's configurations will look exactly the same.

I'm looking to see if there is any way I can put the configuration in a .conf file or something and use that so I don't have to edit the configuration in both modules each time we need to make a change.

I'm currently trying to import the configuration but I don't see any viable options/

Upvotes: 0

Views: 386

Answers (2)

khmarbaise
khmarbaise

Reputation: 97399

The simplest thing is to define the configuration which is common for all execution in a configuration block looks like this:

<project..>
  <modelVersion>4.0.0</modelVersion>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>..</groupId>
          <artifactId>..</artifactId>
          <version>1.0</version>
          <configuration>
            .. Global Configuration which is common for everything
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

So the above should/could be done in your parent pom file of your multi module build. Now in a module which inherits from the parent you can configure it like this:

<project..>
  <modelVersion>4.0.0</modelVersion>

  <build>
    <plugins>
      <plugin>
        <groupId>..</groupId>
        <artifactId>..</artifactId>
        <executions>
          <execution>
            <id>special-exec1</id>
            <goals>..</goals
            <phase>..</phase>
            <configuration>
             ... supplemental configuration which is not part of the parent
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>

So this will define the common configuration in the parent via the pluginManagement and each specialisation can be done in the child.

If you like to overwrite configuration or enhance parts of it this can be done like the following:

<project..>
  <modelVersion>4.0.0</modelVersion>

  <build>
    <plugins>
      <plugin>
        <groupId>..</groupId>
        <artifactId>..</artifactId>
        <executions>
          <execution>
            <id>special-exec1</id>
            <goals>..</goals
            <phase>..</phase>
            <configuration>
              <items combine.children="append">
                 <!-- combine.children="merge" is the default -->
                <item>child-1</item>
              </items>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>

All the details can be read in the POM documentation search for combine.children. It is also possible to prevent the inheritance of the configuration from the parent if you need to see also the previously mentioned documentation.

Upvotes: 1

J Fabian Meier
J Fabian Meier

Reputation: 35805

Your multi-module project probably has a common parent pom.

You can either define the plugin there (with all configuration) - this makes sense if the plugin does not "harm" other modules.

Alternatively, you define the configuration of the plugin in the <pluginManagement> section of the parent pom. Then you only need to define (not configure) the plugin in the relevant modules.

Upvotes: 1

Related Questions