This post originated from an RSS feed registered with Java Buzz
by dion.
Original Post: preGoal/postGoal vs. depends=
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
One thing I really like about Maven is the pre and postGoals support.
I find this functionality MUCH better than hacking around with targets in ant, and having to setup the correct depends="..." path.
With pre/postGoals I don't have to go to the goal which I want to add functionality too. I can intercept it. This is infinitely nicer.
It also makes a lot more sense in Maven, as you have so many predefined goals, and many more plugins ready for you to install.
Example One: Tweaking the way your war is built
Out of the box maven can package a war (in various ways). What if you want to do something "different" than the standard packaging? Well, we wanted to make sure a certain file was put in the classes directory, so we simply use a preGoal:
<preGoal name="war:init">
<copy todir="${build.webinf.classes}">
<fileset dir="${basedir}/../../">
<include name="project.properties"/>
</fileset>
</copy>
</preGoal>
Example Two: Kicking off a pre-compile step
We use XDoclet to generate Hibernate mappings, and can use a simple preGoal around the standard java:compile goal:
<preGoal name="java:compile">
<taskdef name="hibernatedoclet" classname="xdoclet.modules.hibernate.HibernateDocletTask" classpathref="maven.dependency.classpath" />
<hibernatedoclet destdir="${build.webinf.classes}" excludedtags="@version,@author,@todo" force="true" verbose="true">
<hibernate version="2.0" validateXML="true"/>
<fileset dir="${maven.src.dir}/java">
<include name="project/model/*.java"/>
</fileset>
</hibernatedoclet>
</preGoal>
I haven't checked, but it would be really nice to be able to have the preGoal STOP the processing of the actual goal etc. Much nicer.