I have to create multiple packages for a single application built by Maven. At first I use the -Denv
to generate different packages by Maven arguments and I use the resource to include/exclude the resources:
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/${env}.ini></include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
Then I can use
mvn clean package -Denv=dev
mvn clean package -Denv=prod1
mvn clean package -Denv=prod2
mvn clean package -Denv=prod3
.....
However it seems that different packages have to be packaged one by one, which means Maven will spent too much time to build all the packages since we have almost 22 different environments to deploy the application.
Furthermore, each mvn .. package
almost generate the same result like classes,resources except some specified resources like {$env}.ini
, I think it is a waste to run the compile
again and again.
It would be better if we compile all the sources, and resources to the target directory, then generate different packages accordingly, so I thought the maven-assembly-plugin
, generally we will use it like this:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>/src/main/assembly/env.xml</descriptor>
<descriptor>/src/main/assembly/prod1.xml</descriptor>
<descriptor>/src/main/assembly/prod2.xml</descriptor>
......
</descriptors>
</configuration>
</plugin>
Then we have to create 22 descriptors, however these descriptors are too similar with each other, which means there are too many repeated configuration, and it will be difficult once I want to make some general change to all the descriptors.
So I wonder if there is a good alternative to solve this kind of requirements?
You can use the
iterator-maven-plugin
to solve this problem like this:If you use the descriptor like this:
${project.basedir}/@item@.xml
the name will be replaced by every single iteration step so you can have several descriptors...but in your case i assume that you have very similar descriptors so you have the same descriptors without a placeholder which contains only slight differences which can be solve like this in the descriptor itself:as a result you need only a single descriptor. If you have any issues please create issue requests.