Alexander Ites
Alexander Ites

Reputation: 510

Maven list/array property command line override

Is there a way to pass Maven list/array property (e.g. maven-exec-plugin arguments optional parameter) using system properties approach?

I know that the arguments optional parameter can be overridden by exec.args environment variable and commandlineArgs optional parameter can be overridden by exec.args system property. But what I would like to find out if there's a generic Maven command line way to override such list/array properties of plugin configurations using system properties when it comes to other plugins having such list/array configuration properties?

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>execute somebinary</id>
            <phase>compile</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>somebinary</executable>
                <arguments>
                    <argument>arg1</argument>
                    <argument>arg2</argument>
                </arguments>
            </configuration>
        </execution>
    </executions>
</plugin>

I expect to do this by a command like:

mvn exec:exec -Dexec.arguments=arg1,arg2

But it doesn't work as I expect.

Upvotes: 3

Views: 1763

Answers (1)

Mykola Shorobura
Mykola Shorobura

Reputation: 788

Just pul the list of parameters into the double quote "". Example: pom.mxl

<project .....>

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.logicbig.example</groupId>
    <artifactId>mvn-exec-java-example</artifactId>
    <version>1.0-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

main class

public class MyMainClass {
  public static void main(String[] args) {
      Arrays.stream(args).forEach(System.out::println);
  }
}

command line arguments

mvn -q clean compile exec:java -Dexec.mainClass="com.logicbig.example.MyMainClass" -Dexec.args="myArg1 myArg2"

Upvotes: 1

Related Questions