Maven plugin CLI parameter overwriting <configuration> in pom.xml

Marcel Stör :

How does/should Maven plugins behave with regards to the order in which they process configuration options? I would expect that properties passed via CLI overwrite those defined in a <configuration> block in pom.xml.

Here's an example.

pom.xml

<plugin>
    <groupId>group</groupId>
    <artifactId>artifact</artifactId>
    <version>1.2.3</version>
    <executions>
    ...
    </executions>
    <configuration>
        <url>foo.com</url>
    </configuration>
</plugin>

CLI

mvn group:artifact:1.2.3:doit -Dmymojo.url=bar.com

I am currently debugging a plugin (not mine) that gives precedence to the url value defined in the POM rather than the one passed on the CLI. Is that how mojos are supposed to behave i.e. a Maven feature rather than a plugin bug? I didn't find anything mentioned in the ref guide.

Marcel Stör :

As per https://issues.apache.org/jira/browse/MNG-4979 this works as designed. I find it counter-intuitive and don't find the reasons given in MNG-4979 convincing.

If your setup allows to modify the pom.xml you can work around this behavior as suggested by JF Meier (and the issue above).

<properties>
  <mymojo.url>foo.bar</mymojo.url>
</properties>

<plugin>
    <groupId>group</groupId>
    <artifactId>artifact</artifactId>
    <version>1.2.3</version>
    <executions>
    ...
    </executions>
    <configuration>
        <url>${mymojo.url}</url>
    </configuration>
</plugin>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=31765&siteId=1