I am using maven-assembly-plugin
to assemble different artifacts as following:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>configuration-staging</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
<execution>
<id>configuration-production</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
In assembly.xml
, I enabled template filtering:
<fileSets>
<fileSet>
<filtered>true</filtered>
This works great. For example, if I enter ${name}
in one of the resources to be assembled, this is replaced by the name of the project. I could also define properties in pom.xml
, which will be replaced by the plugin.
Now, I would like to have different properties for each execution of maven-assembly-plugin
. For example, I would like to introduce a ${url}
which holds the URL to be used on the target environment (staging
and production
in the example above).
Is this possible? How?
Apparently, it is possible to pass different properties for each execution in the maven-assembly-plugin
as following:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>configuration-staging</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>staging</finalName>
<filters>
<filter>src/main/assembly/staging.properties</filter>
</filters>
</configuration>
</execution>
<execution>
<id>configuration-production</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>production</finalName>
<filters>
<filter>src/main/assembly/production.properties</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
Although this does not answer the generic question, it answers the question specifically for maven-assembly-plugin
.
More can be found on https://maven.apache.org/plugins/maven-assembly-plugin/examples/single/filtering-some-distribution-files.html.