是否可以使用不同的配置参数多次调用相同的maven构建?
我有一个用rpm- maven -plugin创建多个rpm的maven构建。我向它传递一个变量(environment),该变量指定RPM的目标环境:开发、升级或生产。
要为所有环境创建所有RPM,我调用mvn package -Denvironment=... 3次;我想简化一下。如果我可以调用mvn package一次,它将为所有环境构建三个RPM,那就太好了。
你觉得有没有办法做到这一点?
编辑1
到目前为止(基于dm3's great answer),我可以在一个构建中创建三个独立的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>发布于 2011-08-30 15:33:31
我认为在一次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触发)。
https://stackoverflow.com/questions/7239786
复制相似问题