Sunday, March 22, 2009


Sometimes, you need to customize Maven to your need. One way is to write your own plugin. One interesting topic would be to use ant script to create your own plugin. But seems the classpath and environment settings are troublesome here. There are some better ways, for example, the maven-antrun-plugin is really useful for you to twist the build process a bit. The good thing for maven-ant-plugin is that it provides you classpath information so that you can access Maven build classpath.

Our Tellurium core build was broken for a while because GMaven has problem to generate stubs for enum and generic types and our core code has a mix of Java and Groovy code. The maven-antrun-plugin comes to rescue us this time. As a result, we compile the some Java code first using maven-antrun-plugin since some groovy files need to import them. The pom section looks as follows,


<mkdir dir="${basedir}/target/classes"/>
<javac srcdir="${basedir}/src/main/groovy"
destdir="${basedir}/target/classes" classpathref="maven.plugin.classpath">
<include name="**/org/tellurium/exception/*.java" />

Note that the javac ant task requires the tools.jar, as a result, you should add this dependency to maven-antrun-plugin, otherwise, the build will complain about cannot find the javac task.

No comments:

Post a Comment