How do I run a specific goal with a particular configuration in a Maven plugin when I have several configurations for that goal

lukewm picture lukewm · Aug 10, 2010 · Viewed 74.3k times · Source

See plugin config from pom.xml below.

I can do:

mvn myplugin:myGoal

Which runs myGoal (both executions I suppose) but I want to be able to choose either the first or the second executions independently.

I know I can add an id to the execution element, but how do I refer to that id on the command line. I'd like to get to something which does what this imagined command does:

mvn myplugin:myGoal --executionId=1

Is this possible, or am I going about this the wrong way?

        <plugin>
            <groupId>org.myplugin</groupId>
            <artifactId>myplugin-maven-plugin</artifactId>
            <version>1.1.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>myGoal</goal>
                    </goals>
                    <configuration>
                        <myParam>cats</myParam>
                    </configuration>
                </execution>
                <execution>
                    <goals>
                        <goal>myGoal</goal>
                    </goals>
                    <configuration>
                        <myParam>dogs</myParam>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Answer

mdi picture mdi · Nov 10, 2015

Execution of multiple goals from the CLI is now supported in Maven 3.3.1+

mvn exec:java@first-cli
mvn exec:java@second-cli

Where first-cli/second-cli are the execution ids.

https://blog.soebes.de/blog/2015/03/17/apache-maven-3-dot-3-1-features/