Iterations and Maven? Not Possible?
During my experiences with Maven I had a few moments where I wished having some kind of iterations to go over a list of whatever (servers, environments etc.).
After some thinking about the problem i have decided to write my own plugin which will solve the problem. And now I have created such [plugin][github-iterator-maven-plugin].
Currently the plugin can be used by using it from the staging repository. After some feedback i will release it to Maven central. If you find some problems with the plugin you can create a ticket on github or write an email to me. You can use the plugin like the following:
In this case it will iterator over the given list test,prod and dev and call for every item the maven-assembly-plugin.
1<plugin>
2 <groupId>com.soebes.maven.plugins</groupId>
3 <artifactId>iterator-maven-plugin</artifactId>
4 <version>0.1.0</version>
5 <executions>
6 <execution>
7 <phase>package</phase>
8 <goals>
9 <goal>executor</goal>
10 </goals>
11 <configuration>
12 <items>
13 <item>test</item>
14 <item>prod</item>
15 <item>dev</item>
16 </items>
17
18 <pluginExecutors>
19 <pluginExecutor>
20 <plugin>
21 <groupId>org.apache.maven.plugins</groupId>
22 <artifactId>maven-assembly-plugin</artifactId>
23 <version>2.4</version>
24 </plugin>
25 <goal>single</goal>
26 <configuration>
27 <descriptors>
28 <descriptor>${project.basedir}/@item@.xml</descriptor>
29 </descriptors>
30 </configuration>
31 </pluginExecutor>
32 </pluginExecutors>
33 </configuration>
34 </execution>
35 </executions>
36</plugin>
If you need you can execute several plugins as well. Just use an extra pluginExecutor for each of your plugins. So in other words: Iteration or foreach in Maven is solved.