At this point in my career, I am firmly committed to Maven. Occasionally, though, It'd be really nice to break out of the whole pre-packaged plugin model, write some script, maybe call an ANT task, and just get the job done.
Lucky for me, there's a plugin out there that lets me do just that. The Sandflea maven-clojure-plugin lets me execute Clojure scripts as part of a Maven build, with complete access to the Maven API.
Remember the
(ant ...) macro from part 1, and how we used it with the ZIP ANT task? Well, here's an example of using it in a Maven POM to create a ZIP artifact. Yes, this example is a bit contrived, but it's easy enough to understand.<plugin> <groupId>sandflea.clojure</groupId> <artifactId>maven-clojure-plugin</artifactId> <executions> <execution> <id>Create ZIP</id> <goals><goal>execute</goal></goals> <phase>package</phase> <args> <source-dir>${project.basedir}/src/main/assembly</source-dir> <target-zip>${project.build.directory}/${project.artifactId}.zip</target-zip> </args> <configuration> <source> (ns my-project.create-zip (:import [java.io File] [org.apache.tools.ant.taskdefs Zip]) (:use [sandflea.clojure.buildutil])) (ant (Zip.) (.setBasedir (File.(*args* "source-dir"))) (.setDestFile (File.(*args* "target-zip"))) (.compress true) ) </source> </configuration> </execution> </executions> </plugin>
I get to have my cake and eat it too! I know I can rely on steady and predictable Maven to always be there for me, and whenever I need to spice things up a bit, ANT is just a (function) call away. Isn't life sweet?

No comments:
Post a Comment