如何在一次调用中两次调用同一Maven构建 [英] How to invoke the same maven build twice in one call
问题描述
是否可以使用不同的配置参数多次调用同一Maven构建?
我有一个使用rpm-maven-plugin创建多个RPM的Maven构建.我向它传递了一个变量(environment
),该变量指定RPM面向的环境:开发,登台或生产.
要为所有环境创建所有RPM,请致电mvn package -Denvironment=...
3次;我想简化一下.如果我可以一次调用mvn package
,那将很棒,然后依次为所有环境构建三个RPM.
您看到这样做的任何方式吗?
编辑1
到目前为止(基于 dm3的绝妙答案),我可以在一个版本中创建三个具有相同属性的独立RPM.现在的问题是能够为每次执行更改environment
属性.有什么建议吗?
<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执行过程中实现此目标的唯一方法是将插件的多次执行(具有不同的配置)绑定到生命周期阶段,如下所示:
<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
)触发的某些配置文件中.
Is it possible to invoke the same maven build a number of times with different configuration parameters?
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.
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?
Edit 1
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>
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>
You can attach this configuration to some profile triggered by one property (e.g. by mvn package -Denvironment=all
).
这篇关于如何在一次调用中两次调用同一Maven构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!