45

请参阅下面 pom.xml 中的插件配置。

我可以:

mvn myplugin:myGoal

哪个运行 myGoal (我想都是执行),但我希望能够独立选择第一次或第二次执行。

我知道我可以向执行元素添加一个 id,但是我如何在命令行上引用该 id。我想得到一些可以完成这个想象的命令所做的事情:

mvn myplugin:myGoal --executionId=1

这是可能的,还是我走错了路?

        <plugin>
            <groupId>org.myplugin</groupId>
            <artifactId>myplugin-maven-plugin</artifactId>
            <version>1.1.1</version>
            <executions>
                <execution>
                    <id>process-cats</id>
                    <goals>
                        <goal>myGoal</goal>
                    </goals>
                    <configuration>
                        <myParam>cats</myParam>
                    </configuration>
                </execution>
                <execution>
                    <id>process-dogs</id>
                    <goals>
                        <goal>myGoal</goal>
                    </goals>
                    <configuration>
                        <myParam>dogs</myParam>
                    </configuration>
                </execution>
            </executions>
        </plugin>
4

4 回答 4

49

Maven 3.3.1+ 现在支持从 CLI 执行多个目标

mvn exec:java@first-cli
mvn exec:java@second-cli

其中 first-cli/second-cli 是执行 ID。

https://blog.soebes.de/blog/2015/03/17/apache-maven-3-dot-3-1-features/

对于您的示例,命令将是

mvn myplugin:mygoal@process-cats
mvn myplugin:mygoal@process-dogs
于 2015-11-10T10:32:04.823 回答
24

我可以mvn myplugin:myGoalWhich运行 myGoal(我想都执行)

他们都没有(假设他们有 unique id)。执行绑定到一个阶段,您需要运行给定的阶段来触发它们。

我知道我可以向执行元素添加一个 id,但是我如何在命令行上引用该 id。

不支持。在 CLI 上调用的插件可以使用 special 在 POM 中定义非全局default-cli executionId配置,如下所示:

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

这是可能的,还是我走错了路?

不,不可能。在命令行上传递参数或使用配置文件(有或没有上述默认执行)。

参考

于 2010-08-10T13:44:49.120 回答
13

嘿,你可以像这样创建你的目标:-

org.myplugin:myplugin-maven-plugin:1.1.1:myGoal  i.e
<groupId>:<artifactId>:<version>:<yourgoal>

它适用于我的情况......

于 2016-08-17T15:02:50.983 回答
3

The assumption you made that if you call

  mvn myplugin:myGoal

But the problem is that you will get an error message cause the execution have no unique id's (both in this case have the same).

You can reach what you like to do via profiles which you can activate via mvn -PXYZ and mvn -PABC

于 2010-08-10T12:16:18.027 回答