How to execute maven plugin execution directly from command line?

MavenMaven 2

Maven Problem Overview


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

Maven Solutions


Solution 1 - Maven

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.

Solution 2 - Maven

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

Solution 3 - Maven

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: > > > maven-assembly-plugin > > > default-cli > > > jar-with-dependencies > project > > > > > > > This should work in Maven 2.2.0 and > 3.x.

Maybe this will be enough for you.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionartembView Question on Stackoverflow
Solution 1 - MavenJoeView Answer on Stackoverflow
Solution 2 - MavenDimitri DewaeleView Answer on Stackoverflow
Solution 3 - MavenPascal ThiventView Answer on Stackoverflow