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

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/


I can do mvn myplugin:myGoalWhich runs myGoal (both executions I suppose)

None of them (assuming they had unique id). Executions are bound to a phase, you need to run the given phase to trigger them.

I know I can add an id to the execution element, but how do I refer to that id on the command line.

Not supported. What is possible for plugins invoked on the CLI is to define a non global configuration in the POM using the special default-cli executionId, like this:

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <executions>
    <execution>
      <id>default-cli</id>
      <configuration>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
          <descriptorRef>project</descriptorRef>
        </descriptorRefs>
      </configuration>
    </execution>
  </executions>
</plugin>

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

No, not possible. Either pass the parameters on the command line or use profiles (with or without the above default execution).

References

  • Default Plugin Execution IDs
  • http://jira.codehaus.org/browse/MNG-3203
  • http://jira.codehaus.org/browse/MNG-3401

Hey you can create your goal like this:-

org.myplugin:myplugin-maven-plugin:1.1.1:myGoal  i.e
<groupId>:<artifactId>:<version>:<yourgoal>

It works in my case ...