Using Groovy to make Maven2 more modular and readable


Using Groovy to make Maven2 more modular and readable

I started a very very small project this week to increase the usability of Maven 2. I find that although I love Maven as a back-end build processor, I kinda hate the XML configuration file and all the pain that goes with it. So rather than just simply complain, I will also do some token work to fix it. Inspired by Gant, this project attempts to use Groovy to make the creation of POM files easier, more readable, and modular. It will also allow best Maven POM practices to be put into libraries and reused rather than cut and pasted into a POM or painstakingly edited in a GUI. Further, for those who are more adventurous, you can add dynamism to your POM files.With graven (gvn), you can make use of the included standard library of Mavenisms and have this appear within your pom.groovy file:

1     build {
2 plugins {
3 groovy()
4 }
5 }

For example, rather than add this to your POM file to make your Groovy code compile:

1   <build>
2 <plugins>
3 <plugin>
4 <artifactId>maven-antrun-plugin</artifactId>
5 <executions>
6 <execution>
7 <id>compile</id>
8 <phase>compile</phase>
9 <configuration>
10 <tasks>
11 <taskdef name='groovyc' classname='org.codehaus.groovy.ant.Groovyc'>
12 <classpath refid='maven.compile.classpath' />
13 </taskdef>
14 <mkdir dir='${project.build.outputDirectory}' />
15 <groovyc destdir='${project.build.outputDirectory}' srcdir='${basedir}/src/main/groovy' listfiles='true'>
16 <classpath refid='maven.compile.classpath' />
17 </groovyc>
18 </tasks>
19 </configuration>
20 <goals>
21 <goal>run</goal>
22 </goals>
23 </execution>
24 <execution>
25 <id>test-compile</id>
26 <phase>test-compile</phase>
27 <configuration>
28 <tasks>
29 <taskdef name='groovyc' classname='org.codehaus.groovy.ant.Groovyc'>
30 <classpath refid='maven.compile.classpath' />
31 </taskdef>
32 <mkdir dir='${project.build.testOutputDirectory}' />
33 <groovyc destdir='${project.build.testOutputDirectory}' srcdir='${basedir}/src/test/groovy' listfiles='true'>
34 <classpath refid='maven.compile.classpath' />
35 </groovyc>
36 </tasks>
37 </configuration>
38 <goals>
39 <goal>run</goal>
40 </goals>
41 </execution>
42 </executions>
43 </plugin>
44 </plugins>
45 </build>

Voilà. You can check out the complete project here. I’d love help creating the most complete standard library if anyone is interested.