当我有几个针对该目标的配置时,如何在Maven插件中使用特定配置运行特定目标

luk*_*ewm 27 plugins maven-2 pom.xml maven

请参阅下面的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>
                    <goals>
                        <goal>myGoal</goal>
                    </goals>
                    <configuration>
                        <myParam>cats</myParam>
                    </configuration>
                </execution>
                <execution>
                    <goals>
                        <goal>myGoal</goal>
                    </goals>
                    <configuration>
                        <myParam>dogs</myParam>
                    </configuration>
                </execution>
            </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

mdi*_*mdi 28

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

mvn exec:java@first-cli
mvn exec:java@second-cli
Run Code Online (Sandbox Code Playgroud)

first-cli/second-cli是执行ID.

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

  • 链接已死。 (2认同)

Pas*_*ent 21

我可以mvn myplugin:myGoalWhich运行myGoal(我想这两个执行)

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

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

不支持.在CLI上调用的插件可以使用特殊的方法在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>
Run Code Online (Sandbox Code Playgroud)

这是可能的,还是我以错误的方式解决这个问题?

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

参考


小智 7

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

org.myplugin:myplugin-maven-plugin:1.1.1:myGoal  i.e
<groupId>:<artifactId>:<version>:<yourgoal>
Run Code Online (Sandbox Code Playgroud)

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