3

I have a Maven plugin and it is configured in the POM file as

<build>
    <plugins>
        <plugin>
            <groupId>com.example</groupId>
            <artifactId>example-maven-plugin</artifactId>
            <configuration>
                <scriptsPath>scripts</scriptsPath>
            </configuration>
        </plugin>
    </plugins>
</build>

Now I want to override that scriptsPath from from command line so I run

mvn -X example-maven-plugin:goal -DscriptsPath=scripts1

I can see that value of the scriptsPath is still scripts and not scripts1. Could the configuration parameter be overriden from the command line ?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
EvgeniySharapov
  • 3,078
  • 3
  • 27
  • 38
  • 1
    it could, but it depends on the maven plugin implementation (and support) for it and whether it applies the same name as the xml element name (which is not always the case). To be checked on the plugin official documentation, if any – A_Di-Matteo Jan 27 '16 at 21:30
  • If `example-maven-plugin` supports command line parameters, you can see their names by running `mvn help:describe -Dcmd=example-maven-plugin:goal -Ddetail` – darw Apr 30 '21 at 09:51

1 Answers1

7

Unfortunately, there is no general way to override maven plugin configuration by using properties. If the plugin documentation does not explicitly allow you to use a property to set the configuration value you can use following pattern:

<properties>
    <scripts.path>scripts</scripts.path>
</properties>
<build>
    <plugins>
        <plugin>
            <groupId>com.example</groupId>
            <artifactId>example-maven-plugin</artifactId>
            <configuration>
                <scriptsPath>${scripts.path}</scriptsPath>
            </configuration>
        </plugin>
    </plugins>
</build>

and then execute maven as

mvn -X example-maven-plugin:goal -Dscripts.path=scripts1
Stepan Vavra
  • 3,884
  • 5
  • 29
  • 40
  • 1
    That's exactly what the linked duplicate is answering. You should flag as duplicate instead. – Tunaki Jan 27 '16 at 21:40
  • 3
    Well, it uses the same approach. However, in the linked answer, it is the `` what is set through a property, which may look like an answer to a different question to unexperienced maven users. That is why I answered his question without marking it as duplicate. – Stepan Vavra Jan 27 '16 at 21:43
  • Yeah, looks like it is a duplicate. and @StepanVavra approach is the one that works. – EvgeniySharapov Jan 27 '16 at 21:45
  • @Tunaki the other question isn't too useful for someone looking to solve this issue (longer than it needs to be, overwrite instead of override, no pom given in the question) and is quite different, ie how to override a property vs how to override a configuration. and stephan's answer is perfect - he gives the factually correct answer ("no general way"), and a workaround using properties – nqzero Oct 01 '18 at 18:30