I\'m having a problem with this very redundant maven configuration.
The application I\'m working on sometimes gets built for environments that need alternate resourc
Assuming the following structure:
src/
└── main
├── assembly
│ └── iterator.xml
└── environment
├── dev
│ └── server.properties
├── pretest
│ └── server.properties
├── production
│ └── server.properties
├── qa
│ └── server.properties
└── test
└── server.properties
where you can use the following assembly-descriptor like this:
<assembly>
<id>${item}</id>
<formats>
<format>war</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>true</unpack>
<useProjectArtifact>false</useProjectArtifact>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<outputDirectory>WEB-INF</outputDirectory>
<directory>${basedir}/src/main/environment/${item}/</directory>
<includes>
<include>**</include>
</includes>
</fileSet>
<fileSet>
<outputDirectory>WEB-INF</outputDirectory>
<directory>${project.build.directory}/environment/${item}</directory>
<includes>
<include>**</include>
</includes>
</fileSet>
</fileSets>
</assembly>
using the iterator-maven-plugin will solve the problem:
<build>
<plugins>
<plugin>
<groupId>com.soebes.maven.plugins</groupId>
<artifactId>iterator-maven-plugin</artifactId>
<version>0.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>executor</goal>
</goals>
<configuration>
<items>
<item>dev</item>
<item>test</item>
<item>qa</item>
<item>production</item>
<item>pretest</item>
</items>
<pluginExecutors>
<pluginExecutor>
<goal>single</goal>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
<configuration>
<descriptors>
<descriptor>${project.basedir}/src/main/assembly/iterator.xml</descriptor>
</descriptors>
</configuration>
</pluginExecutor>
</pluginExecutors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The iterator-maven-plugin is available via maven central. I think you can adapt the above configuration/structure to your problem.
Having messed with a similar problem for a long time, I got rid of tons of XML code, using the following workarounds:
Create the same zip archive for all the environments; resources should be extracted or accessed depending on environment (server's hostname, environment variables, etc.)
Create a single JAVA/Groovy class that will build all the necessary environment-specific assemblies and run it through maven-exec-plugin execution.