Exporting a Maven build for users who don’t have Maven

I came across this interesting JIRA issue raised on the Spring Framework area: “Do NOT migrate Spring to purely Maven build. It will be a travesty!” Quote:

This could well be a total disaster for Spring. There are many projects that have suffered at the hands of Maven which is revered by some and hated by just as many.

Abandoning pure ANT builds will be a major mistake.

Juergen’s response towards the end was heartening – I’m sure it was good news for a lot of other developers out there as well:

Guys, no worries – I’m a dedicated Ant lover myself :-)

I have got to say this for the benefit of a certain few people who may be reading this post – who I have personally argued with (pro Ant): I told you so :)

Anyway, while scanning the amusing back and forth of comments on that JIRA bug report, I started thinking of how I could extend my custom Maven and Ant integration approach to provide a solution to what appears to be the main gripe of Spring fans against Maven – that moving to a Maven build would prevent bundling all dependencies.

Well, it was easier than I thought. Modifying the plugin, I was able to write out out a properties file containing a list of all the JAR files required for the build. Then, all it takes is 3 lines of Ant code to copy this fileset of JARs from your local Maven repository into any project relative folder that you want, say “lib”. For example, if you have a comma-delimited list of files as “all.jars”:

<copy todir="lib">
    <fileset dir="${m2.repo}" includes="${all.jars}" casesensitive="false"/>
</copy>

This preserves the long pathnames e.g. “lib/org/springframework/spring/2.0-rc2/spring-2.0-rc2.jar” so it is very much like the Spring full download “with dependencies” we are used to.

So now I can easily hand off the project to a developer who does not have internet acess or Maven installed – a zip of the source including the “lib” folder should be enough. And a one line change in the properties file that the custom Maven plugin generates – which is setting “m2.repo=lib” should be sufficient to get the Ant driven build working for anyone.

If you are interested in getting hold of the latest source code for the Maven plugin, you can find details here. Note that this is actually developer documentation for another open-source project, but it includes the Subversion URL for the plugin source and how to install it.

4 Responses to Exporting a Maven build for users who don’t have Maven

  1. Taylor Gautier says:

    What’s wrong with the assembly plugin? It copies all of the dependencies for you and produces the output in any format you want – directory, zip, tar, tgz, jar etc.

    It’s highly flexible, and can be made to include any kind of package artifacts you want from source, resources to the pom itself.

  2. Peter Thomas says:

    My approach allows an end user to use Ant for all build operations. Since I had already implemented a plugin designed to work with Ant, I just had to tweak it a little to get the “export” feature.

  3. kocka says:

    nice work! :)

    (I am a maven-user :))

  4. Pingback: How to shutdown HSQLDB from Ant « Incremental Operations

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: