Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 369
rustyx Avatar asked Jan 11 '11 16:01

rustyx


People also ask

How do I override plugin from parent pom?

Overriding configurations from a parent pom can be done by adding the combine. self="override" attribute to the element in your pom. It appears that for Maven2. 2.1 if you do this in a profile it doesn't merge with plugins defined in parent profiles but overrides them.

What is pluginManagement in Pom?

pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one.

In which section of POM do you configure Maven plugins?

Build plugins They execute during the build process and should be configured in the <build/> element of pom.

Are plugins inherited from parent pom?

1. Overview. Maven allows us to build a project using the concept of inheritance. When a parent POM defines a plugin, all of the child modules inherit it.


2 Answers

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.

like image 24
Stefan Birkner Avatar answered Oct 02 '22 12:10

Stefan Birkner


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>
like image 149
rustyx Avatar answered Oct 02 '22 11:10

rustyx