如何在一次调用中两次调用相同的 Maven 构建 [英] How to invoke the same maven build twice in one call

查看:32
本文介绍了如何在一次调用中两次调用相同的 Maven 构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用不同的配置参数多次调用同一个 maven build?

Is it possible to invoke the same maven build a number of times with different configuration parameters?

我有一个 maven 构建,它使用 rpm-maven-plugin 创建了多个 RPM.我向它传递了一个变量 (environment),该变量指定了 RPM 的目标环境:开发、登台或生产.

I have a maven build that creates a number RPMs with the rpm-maven-plugin. I pass it a variable (environment) which specifies which environment the RPM is targeted for: development, staging or production.

要为所有环境创建所有 RPM,我调用 mvn package -Denvironment=... 3 次;我想简化一下.如果我能调用一次 mvn package 那就太好了,反过来,它会为所有环境构建三个 RPM.

To create all RPMs for all environments, I call mvn package -Denvironment=... 3 times; and I'd like to simplify that. It would be great if I could call mvn package once, and it, in turn, would build three RPMs for all environments.

你认为有什么方法可以做到这一点吗?

Do you see any way of doing this?

到目前为止(基于 dm3 的好答案),我可以在一次构建中创建三个具有相同属性的独立 RPM.现在的问题是能够为每次执行更改 environment 属性.有什么建议吗?

So far (based on dm3's great answer), I can create three independent RPMs in one build, with the same properties. The problem now is to be able to change the environment property for each execution. Any suggestions?

<project>
  <properties>
    <!-- Default Environment -->
    <environment>development</environment>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>rpm-maven-plugin</artifactId>
        <version>2.1-alpha-1</version>
        <executions>
          <execution>
            <phase>package</phase>
            <id>package-development</id>
            <goals><goal>rpm</goal></goals>
          </execution>

          <execution>
            <phase>package</phase>
            <id>package-staging</id>
            <goals><goal>rpm</goal></goals>
          </execution>

          <execution>
            <phase>package</phase>
            <id>package-production</id>
            <goals><goal>rpm</goal></goals>
          </execution>
        </executions>
      </plugin>
    </plugins>

    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>rpm-maven-plugin</artifactId>
          <version>2.1-alpha-1</version>
          <extensions>true</extensions>

          <configuration>
          ... VERY LONG CONFIG ...
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

推荐答案

我相信在一个 Maven 执行期间实现这一目标的唯一方法是将插件的多个执行(具有不同的配置)绑定到一个生命周期阶段,如下所示:

I believe the only way to achieve that during one maven execution is to bind several executions of the plugin (with different configurations) to a lifecycle phase, like this:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <executions>
                <execution>
                    <phase>test</phase>
                    <id>test-1</id>
                    <configuration>
                        ...
                    </configuration>
                    <goals><goal>test</goal></goals>
                </execution>
                <execution>
                    <phase>test</phase>
                    <id>test-2</id>
                    <configuration>
                        ...
                    </configuration>
                    <goals><goal>test</goal></goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    ...
</build>

您可以将此配置附加到由一个属性触发的某个配置文件(例如,通过 mvn package -Denvironment=all).

You can attach this configuration to some profile triggered by one property (e.g. by mvn package -Denvironment=all).

这篇关于如何在一次调用中两次调用相同的 Maven 构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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