mojohaus / exec-maven-plugin

Exec Maven Plugin
https://www.mojohaus.org/exec-maven-plugin/
Apache License 2.0
170 stars 98 forks source link

Passing argument -p to java application #334

Open javaguru-ch opened 2 years ago

javaguru-ch commented 2 years ago

When trying to use the exec goal in order to run a java application the argument -p is not passed to the java application as an argument. I attached a minimal maven project to reproduce the issue: ExecMavenIssueTest.zip

Java application for testing:

package test.it.out;

import java.util.Arrays;

public class MainApp {
    public static void main(String... args) {
        System.out.println("Arguments: " + Arrays.toString(args));
    }
}

exec-maven-plugin configuration:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>3.1.0</version>
    <executions>
        <!-- This only works with 3.0.0 but not with 3.1.0! -->
        <execution>
            <id>execution-no-quotes</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>java</executable>
                <arguments>
                    <argument>-classpath</argument>
                    <classpath/>
                    <argument>test.it.out.MainApp</argument>
                    <argument>-p</argument>
                    <argument>-q</argument>
                    <argument>-r</argument>
                </arguments>
                <classpathScope>runtime</classpathScope>
            </configuration>
        </execution>
        <!-- When quoting the "-p" argument, it works with 3.1.0 too! -->
        <execution>
            <id>execution-with-quotes</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>java</executable>
                <arguments>
                    <argument>-classpath</argument>
                    <classpath/>
                    <argument>test.it.out.MainApp</argument>
                    <argument>"-p"</argument>
                    <argument>-q</argument>
                    <argument>-r</argument>
                </arguments>
                <classpathScope>runtime</classpathScope>
            </configuration>
        </execution>
    </executions>
</plugin>

Output for 3.1.0:

...
[INFO] 
[INFO] --- exec-maven-plugin:3.1.0:exec (execution-no-quotes) @ runner ---
Arguments: [-p, -r]
[INFO] 
[INFO] --- exec-maven-plugin:3.1.0:exec (execution-with-quotes) @ runner ---
Arguments: [-p, -q, -r]
...

Output for 3.0.0:

...
[INFO] 
[INFO] --- exec-maven-plugin:3.0.0:exec (execution-no-quotes) @ runner ---
Arguments: [-p, -q, -r]
[INFO] 
[INFO] --- exec-maven-plugin:3.0.0:exec (execution-with-quotes) @ runner ---
Arguments: [-p, -q, -r]
...
pzygielo commented 2 years ago