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?
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
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With