当我为目标配置了多个配置时,如何使用Maven插件中的特定配置运行特定目标 [英] How do I run a specific goal with a particular configuration in a Maven plugin when I have several configurations for that goal

查看:70
本文介绍了当我为目标配置了多个配置时,如何使用Maven插件中的特定配置运行特定目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

See plugin config from pom.xml below.

我可以做到:

mvn myplugin:myGoal

哪个运行myGoal(我猜这两个执行程序),但我希望能够独立选择第一个或第二个执行程序.

Which runs myGoal (both executions I suppose) but I want to be able to choose either the first or the second executions independently.

我知道我可以在执行元素中添加一个ID,但是如何在命令行上引用该ID.我想做一些能实现此想象的命令的事情:

I know I can add an id to the execution element, but how do I refer to that id on the command line. I'd like to get to something which does what this imagined command does:

mvn myplugin:myGoal --executionId=1

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

Is this possible, or am I going about this the wrong way?

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

推荐答案

我可以做mvn myplugin:myGoalWhich运行myGoal(我猜这两个执行程序)

I can do mvn myplugin:myGoalWhich runs myGoal (both executions I suppose)

都不存在(假设它们具有唯一的id).执行被绑定到一个阶段,您需要运行给定的阶段来触发它们.

None of them (assuming they had unique id). Executions are bound to a phase, you need to run the given phase to trigger them.

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

I know I can add an id to the execution element, but how do I refer to that id on the command line.

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

Not supported. What is possible for plugins invoked on the CLI is to define a non global configuration in the POM using the special default-cli executionId, like this:

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

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

Is this possible, or am I going about this the wrong way?

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

No, not possible. Either pass the parameters on the command line or use profiles (with or without the above default execution).

  • Default Plugin Execution IDs
  • http://jira.codehaus.org/browse/MNG-3203
  • http://jira.codehaus.org/browse/MNG-3401

这篇关于当我为目标配置了多个配置时,如何使用Maven插件中的特定配置运行特定目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆