Tapestry Training -- From The Source

Let me help you get your team up to speed in Tapestry ... fast. Visit howardlewisship.com for details on training, mentoring and support!

Thursday, May 20, 2004

Maven-like downloads for Ant

One of the key features of Maven that I like is that it will download dependencies for you automatically.

I'm just starting to convert HiveMind from Maven back to Ant and this was very hard to do. I want to download a file, just if it doesn't exist locally (or is out of date), compute the MD5 sum while it downloads, and compare that to an MD5 sum stored on the server.

There was an existing project, greedo that may have done some or all of that ... but it has stalled in that "nearly-done" open source state so many projects reach. No activity in the last nine months. Broken home page. No documentation. I got it to build, but I had to hack their broken Ant build files. Also, I think the <macrodef> features of Ant 1.6 trumps a lot of the functionality in greedo, and I wanted more flexibility with respect to where I get files and how they are stored.

Anyway, I took a peek at the existing Get task of Ant and created a Grabber task. That's a start and it will be necessary in order to build HiveMind in the future. For the moment, it is available as http://howardlewisship.com/downloads/AntGrab.zip. This includes source and a JAR, ant-grabber.jar, that must be placed in ANT_HOME/lib.

A request has come in to discuss how it is used. Now, Grabber is super-alpha, but here's a portion of my Ant-based build environment to demonstrate how it is used:

	<available classname="org.apache.ant.grabber.Grabber" property="grabber-task-available"/>
	<fail unless="grabber-task-available" message="Grab task (from ant-grabber.jar) not on Ant classpath."/>
	<taskdef classname="org.apache.ant.grabber.Grabber" name="grabber"/>

	<!-- macro for downloading a JAR from maven's repository on ibiblio. -->
	<macrodef name="download-from-ibiblio">
		<attribute name="jar" description="The name of the JAR to download."/>
		<attribute name="group-id" description="The Maven group-id containing the JAR."/>
			<mkdir dir="${external.lib.dir}"/>



Later I use the macro as follows:

		<download-from-ibiblio jar="commons-logging-1.0.3.jar" group-id="commons-logging"/>
		<download-from-ibiblio jar="javassist-2.6.jar" group-id="jboss"/>
		<download-from-ibiblio jar="xml-apis-1.0.b2.jar" group-id="xml-apis"/>
		<download-from-ibiblio jar="servletapi-2.3.jar" group-id="servletapi"/>
		<download-from-ibiblio jar="werkz-1.0-beta-10.jar" group-id="werkz"/>
		<download-from-ibiblio jar="oro-2.0.6.jar" group-id="oro"/>
		<download-from-ibiblio jar="easymock-1.1.jar" group-id="easymock"/>
		<download-from-ibiblio jar="log4j-1.2.7.jar" group-id="log4j"/>


Matt Raible said...

Hmmm, any documentation or sample XML on how you're using it?

Mircea Toma said...


Have a look here: https://synthetis.dev.java.net/source/browse/synthetis/tool/jarstore/ . You can see how it's used here: https://synthetis.dev.java.net/source/browse/synthetis/component/saxparser/implementation/tagsoup/ . The metadata respository you can find it here: https://synthetis.dev.java.net/source/browse/synthetis/www/repository/meta/ .
By the way, it supports Maven style library repositories, repository referrals, and transitive dependencies and conflicts. The only problem is that I didn't create any documentation.
Good luck ... ;)

Brett Porter said...

Howard, any reason you are switching back to Ant? We haven't heard from you on the Maven lists for a while.

Brian Pontarelli said...

I also created something very similar as an extension to ant. It is called Savant (didn't realize there was another ant extension called Savant when I was writing it and I haven't seen activity on that project for a while so hopefully I won't step on too many toes).

The project is part of Verge and the docs and such are over at http://www.inversoft.com

Matthew Ryan said...

This Grabber Task you have created is exactly what I am looking for. Unfortunately it seems the link you have provided is no longer valid.

Any chance of making it available again or providing another link?



Howard said...

The Maven team now has official Ant tasks for accessing files within Maven repositories.