【问题标题】:How to execute maven plugin execution directly from command line?如何直接从命令行执行maven插件执行?
【发布时间】:2011-03-11 03:22:32
【问题描述】:

我有一个配置了执行的插件(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

【问题讨论】:

标签: maven maven-2


【解决方案1】:

此功能已将 implemented 替换为 MNG-5768,并且在 Maven 3.3.1 中可用。

变化将:

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

所以,在你的情况下:

mvn antrun:run

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

mvn antrun:run@my-execution

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

【讨论】:

  • 从工件ID“maven-antrun-plugin”我们怎么知道应该在mvn antrun:run中使用的只是“antrun”?
  • @mks-d 请参阅 pluginGroups 了解为什么 org.apache.maven.plugins:maven-antrun-plugin 可以称为 antrun。
  • @Joe 谢谢,除了插件组之外,显然还有Plugin Prefix Resolution 机制...
【解决方案2】:

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

mvn groupId:artifactId:version:goal

更多信息请访问:Development guide for Maven plugins

【讨论】:

  • 但我怎样才能准确地运行“default-cli”执行?如果插件定义中有多个执行。
  • 我一直在努力让 Spring Boot Jasypt 实用程序插件运行,无论出于何种原因,我能让它被 Maven 识别的唯一方法就是遵循上面的建议。仅仅直接指定目标 (mvn jasypt:encrypt ...) 是不够的。谢谢@dimitri-dewaele。
  • 运行特定执行的问题;您的答案将运行为目标配置的所有执行。
【解决方案3】:

Default+Plugin+Execution+IDs 捕获了您要查找的内容,但据我所知,目前不支持。不过根据MNG-3401的cmets(读到最后):

对于直接从 命令行,你可以提供 使用 POM 进行配置 executionId: '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>

这应该在 Maven 2.2.0 和 3.x.

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

【讨论】:

  • 如果你的答案是正确的,那不完全是问题事件;)。
猜你喜欢
  • 1970-01-01
  • 2012-11-02
  • 1970-01-01
  • 1970-01-01
  • 2011-08-03
  • 2015-04-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多