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

我有一个插件(antrun)与执行配置,其中有一个 id,并没有绑定到任何阶段。我可以直接从命令行执行此操作吗?

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

比如:

mvn my-execution

至少

mvn magicplugin:execute -DexecutionId=my-execution
106788 次浏览

你正在寻找的是捕获在 默认 + 插件 + 执行 + ID但据我所知,目前不支持。然而,根据 MNG-3401的评论(读到最后) :

对于直接从 命令行,您可以提供 配置从 POM 使用 ExectionId: ‘ default-cli’如下:

<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.

也许这对你来说就足够了。

这个功能一直是 实施作为 MNG-5768,并且在 Maven 3.3.1中可用。

这一变化将会:

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

所以,对你来说:

mvn antrun:run

使用 default-cli执行 ID,并且:

mvn antrun:run@my-execution

使用在您的 pom 中配置的执行。

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

mvn groupId:artifactId:version:goal

更多信息请访问: Maven 插件开发指南