111

I have a plugin (antrun) with an execution configured which has an id and is not bound to any phase. Can I execute this execution directly from the command line?

<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <executions>
    <execution>
      <id>my-execution</id>
      ...
    </execution>
  </executions>
</plugin>

An run it with something like:

mvn my-execution

or at least

mvn magicplugin:execute -DexecutionId=my-execution
Naman
  • 21,685
  • 24
  • 196
  • 332
artemb
  • 8,953
  • 9
  • 45
  • 68
  • 1
    Does this answer your question? [Run a single Maven plugin execution?](https://stackoverflow.com/questions/3779369/run-a-single-maven-plugin-execution) – Jens Schauder Oct 29 '21 at 14:29

3 Answers3

153

This functionality has been implemented as MNG-5768, and is available in Maven 3.3.1.

The change will:

extend direct plugin invocation syntax to allow optional @execution-id parameter, e.g., org.apache.maven.plugins:maven-remote-resources-plugin:1.0:process@executionId.

So, in your case:

mvn antrun:run

uses the default-cli execution ID, and:

mvn antrun:run@my-execution

uses the execution configured in your pom.

mkobit
  • 39,564
  • 9
  • 145
  • 144
Joe
  • 26,561
  • 11
  • 64
  • 84
  • 6
    From the artifact ID "maven-antrun-plugin" how do we know that it is just "antrun" that should be used in `mvn antrun:run`? – mks-d Feb 08 '19 at 21:53
  • 1
    @mks-d see [`pluginGroups`](https://maven.apache.org/settings.html#Plugin_Groups) for why `org.apache.maven.plugins:maven-antrun-plugin` can be referred to as `antrun`. – Joe Feb 09 '19 at 10:53
  • 1
    @Joe thanks, on top of plugin groups there is also the [Plugin Prefix Resolution](https://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html) mechanism apparently... – mks-d Feb 12 '19 at 14:25
76

The most direct means of executing your maven plugin is to specify the plugin goal directly on the command line.

mvn groupId:artifactId:version:goal

More information at: Development guide for Maven plugins

Dimitri Dewaele
  • 9,771
  • 18
  • 75
  • 123
  • 3
    But how can I run exactly "default-cli" execution? If there are several executions in the plugin definition. – Anton Balashov Jun 27 '17 at 15:38
  • I was fighting to get a Spring Boot Jasypt utility plugin to run, and for whatever reason, the only way I could get it to get recognized by Maven was by following the advice above. Just specifying the goal directly (`mvn jasypt:encrypt ...`) wasn't enough. Thanks @dimitri-dewaele. – Mike Feb 20 '20 at 12:13
  • The question asked for running a specific execution; your answer will run all executions configured for a goal. – toolforger Dec 12 '20 at 07:36
  • How do you add configuration ? – serv-inc Feb 15 '22 at 10:42
17

What you're looking for is captured in Default+Plugin+Execution+IDs but to my knowledge currently not supported. However, according to the comments of MNG-3401 (read them until the end):

for mojos invoked directly from the command line, you can supply configuration from the POM using the executionId: 'default-cli' 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>

This should work in Maven 2.2.0 and 3.x.

Maybe this will be enough for you.

pitseeker
  • 2,407
  • 25
  • 33
Pascal Thivent
  • 549,808
  • 132
  • 1,049
  • 1,115