如何直接从命令行执行maven插件执行?

art*_*emb 85 maven-2

我有一个插件(antrun),其执行配置具有id并且不绑定到任何阶段.我可以直接从命令行执行此执行吗?

<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <executions>
    <execution>
      <id>my-execution</id>
      ...
    </execution>
  </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

用它来运行它:

mvn my-execution
Run Code Online (Sandbox Code Playgroud)

或至少

mvn magicplugin:execute -DexecutionId=my-execution
Run Code Online (Sandbox Code Playgroud)

Joe*_*Joe 118

此功能已被实现MNG-5768,并且可在Maven的3.3.1.

变化将:

扩展直接插件调用语法以允许可选的@ execution-id参数,例如,org.apache.maven.plugins:maven-remote-resources-plugin:1.0:process @ executionId.

所以,在你的情况下:

mvn antrun:run
Run Code Online (Sandbox Code Playgroud)

使用default-cli执行ID,并:

mvn antrun:run@my-execution
Run Code Online (Sandbox Code Playgroud)

使用你的pom中配置的执行.

  • 从工件ID“maven-antrun-plugin”我们怎么知道它只是“antrun”应该在`mvn antrun:run`中使用? (4认同)
  • @Joe谢谢,在插件组之上,显然还有[插件前缀解析](https://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html)机制...... (2认同)

Dim*_*ele 38

执行maven插件的最直接方法是直接在命令行上指定插件目标.

mvn groupId:artifactId:version:goal
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅:Maven插件开发指南

  • 但是我怎样才能准确地运行“default-cli”执行呢?如果插件定义中有多个执行。 (2认同)

Pas*_*ent 14

您正在寻找的内容是在Default + Plugin + Execution + ID中捕获的,但据我所知,目前不支持.但是,根据MNG-3401的评论(直到最后阅读):

对于直接从命令行调用的mojos,您可以使用executionId:'default-cli'从POM提供配置,如下所示:

<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>
Run Code Online (Sandbox Code Playgroud)

这应该适用于Maven 2.2.0和3.x.

也许这对你来说已经足够了.