rustyx
rustyx

Reputation: 85531

Override Maven plugin configuration defined in the pom pluginManagement from the command line

The POM that my project inherits contains some <pluginManagement> for the release plugin that specifies some additional arguments.

My question is: Is there a way to override the arguments parameter from the command line in this case?

The parent POM has this:

<pluginManagement>
    <plugin>
        <artifactId>maven-release-plugin</artifactId>
        <configuration>
            <arguments>-Prelease</arguments>
        </configuration>
    </plugin>
</pluginManagement>

Due to that the command line argument doesn't work:

mvn release:prepare -Darguments="-Pmock -Prelease"

The -Darguments="-Pmock -Prelease" part has no effect. When arguments is not already specified, it works.

It is not possible for me to modify the parent POM or not to use it.

Upvotes: 24

Views: 15132

Answers (2)

Stefan Birkner
Stefan Birkner

Reputation: 24550

You cannot override a configuration, which is already set in the POM (see Maven Bug MNG-4979). You may use variables in order to avoid this behaviour. The snippet of your answer makes use of it.

Upvotes: 11

rustyx
rustyx

Reputation: 85531

Found the solution. In my POM I add this which overrides the settings in the parent POM and allows to specify additional arguments on command line, e.g. -Darguments=-Pmock

<pluginManagement>
    <plugin>
        <artifactId>maven-release-plugin</artifactId>
        <configuration>
            <arguments>${arguments} -Prelease</arguments>
        </configuration>
    </plugin>
</pluginManagement>

Upvotes: 17

Related Questions