ecbrodie
ecbrodie

Reputation: 11876

Maven share configuration between multiple plugin executions

If I have multiple executions of a Maven plugin and they share at least one of the same configuration values, is there a way for me to share this configuration between all executions of the plugin.

Consider the trivial case of a build plugin with two executions:

<plugin>
    <!-- ID, version... -->
    <executions>
        <execution>
            <id>ID1</id>
            <configuration>
                <myConfig>foo</myConfig>
                ...
            </configuration>
        </execution>
        <execution>
            <id>ID2</id>
            <configuration>
                <myConfig>foo</myConfig>
                ...
            </configuration>
        </execution>
    </executions>
</plugin>

How can I rewrite this so that both the ID1 and the ID2 executions use the same value for the myConfig configuration?

Upvotes: 4

Views: 1979

Answers (2)

Dmitry
Dmitry

Reputation: 2993

Why not move common configuration outside concrete executions?

<plugin>
    <!-- ID, version... -->
    <configuration>
        <commonConfig>foo</commonConfig>
    </configuration>
    <executions>
        <execution>
            <id>ID1</id>
            <configuration>
                <specificConfig>bar</specificConfig>
            </configuration>
        </execution>
        <execution>
            <id>ID1</id>
            <configuration>
                <specificConfig>baz</specificConfig>
            </configuration>
        </execution>
    </executions>
</plugin>

It works for some plugins I use (e.g. gmaven-plugin) and in Maven documentation I haven't found any evidence it shouldn't work.

Upvotes: 6

Lee Meador
Lee Meador

Reputation: 12985

Use properties that are set like this somewhere before they are used:

<project>
    ...
    <properties>
        <myConfig>foo</myConfig>
    </properties>
    ...
</project>

Then use it like this

<execution>
    <id>ID1</id>
    <configuration>
        <myConfig>${myConfig}</myConfig>
         ...
    </configuration>
</execution>
<execution>
    <id>ID2</id>
    <configuration>
        <myConfig>${myConfig}</myConfig>
         ...
    </configuration>
</execution>

Upvotes: 1

Related Questions