Skip to main content

Ant and Maven, history of a truce

Posted by fabriziogiudici on March 21, 2009 at 5:54 AM PDT

Necessary introduction: this post is not about Ant vs Maven (it would be Yet Another Completely Useless Discussion), but on how it is possible to find a diplomatic agreement between antists and mavenists. So, please don't comment about how Maven is better/worse than Ant, as everybody knows that such discussions never reach a final conclusion and most people stays with their original ideas; instead, please comment about the idea at the end of the post.

First, the background. Friends often say I'm a contrarian, because e.g. I'm known to hate football, Apple, FaceBook, or Twitter, and Maven is in the list of hated things as well. Indeed I don't see myself as a true contrarian, rather as a pretty picky person who'd like to do things with awareness. For this reason, I wouldn't say I "hate" things (even though I use the term for simplicity), being my decisions based on rationality rather than feelings. For instance, I was not against FaceBook in the principle and I even subscribed an invitation some friends sent me at some points. After learning more about it I decided it was useless and dangerous. To prove my point further, I've got some opposite example: when Gianugo Rabellino first suggested me to use Wicket I was skeptical. I can say I even "hated" Wicket for the first two/three days I was playing with it since some things seemed pretty absurd. Nevertheless, I do listen to reputable persons such as Gianugo, so I literally forced myself to trying it a bit longer before giving up. The result is that Wicket has been my primary choice for web applications for two years now.

In the same way, lot of reputable friends from JUG Milano, JUG Genova and JUG Torino advocate for the use of Maven, and indeed I tried to use it a number of times (also because NetBeans has a pretty good support for it, to be greatly improved in 6.7). Nevertheless, I've always found it a completely useless piece of complexity, as none of the alleged "features" of Maven is a positive point in my opinion.

If you're curious, my biggest point against Maven is about reproducibility and control. Everything in my projects must be completely reproducible, so everything but the JDK is committed in Subversion, including QA tools such as Cobertura or Findbugs; I don't want to depend on somebody else's repository, neither I want to waste time in setting up mine; I want to always understand what's happening and be able to make a temporary patch, an easy thing with Ant and headache with Maven; at last, I've refactored my build environment in the tools subsection of OpenBlueSky and I need about one minute to set up a new project with the same standardized structure, so archetipes don't give me any real plus.

A few days ago I made another attempt: another small piece of blueMarine is of interest for a paying customer who uses Maven. Since this is originating yet another spin-off subproject, which is tiny, I supposed that tolerating Maven there was acceptable. But when I tried to integrate the Cobertura plugin for Hudson and found that not only it was broken, but also broke the whole Hudson (as confirmed by others), I got literally furious. Yes, technically it's not a Maven bug, but the quality of a product is related also to its ecosystem, and I have never found any serious bug with Ant while it seems there's always something broken around Maven.

Patiently answering to my rants in a private email exchange, Marcello Teodori gave me a good hint: try to make Maven and Ant co-exist. He's doing the same thing in VqWiki.

So, since Maven is the intolerant one while Ant is flexible, the solution I'm trying is to keep the same directory layout as Maven (e.g. src/main/java) and make Ant to work on it. pom.xml only contains stuff for making a build and testing it, while build.xml also contains all the Hudson stuff in the way I like. Maven will use a repository for libraries, while Ant will use jar files committed with the project. I'll develop the project with Ant, but take also care of not breaking Maven compability (with Hudson help), so my customer will be able to use Maven. If the thing proves to work, I might even extend this to my other JSE projects.


I have somehow managed to have ant and maven together but with difficulty. First problem was directory layout for maven. With ant, I produced a jar and then a war adding just a web.xml file and some dependencies from a directory. My understanding of Maven is that it needs 2 directory layouts and 2 pom files to produce the jar and then the war. SVN links with svn:external property came to the rescue to place files in directories for maven without too much duplicity. Second problem was the content of jar: the jar needs to contain some files such as licence, readme.txt (or perhaps a signature/certificate for you) and even with help of a maven expert it does not seems easy. So I use the maven antrun plugin to make jar, war and zip. But there was the third problem. Third problem was that maven antrun has strange behaviour (as other maven plugins). Some basic ant properties are not defined (ant.home in maven 2.0.10) and it launches ant in a jre even if maven is launched in a jdk (I suspect a maven revenge here). A system.path dependency with tools.jar is needed in antrun configuration (with a profile if mac-os). There is no way for the pom to be shorter than ant script : just think of src files in utf-8, but I can do easy reporting with maven.

I implemented successfully that strategy in the past. Specially ending 2006. Netbeans plugin and maven itself were... let's say a little different. Whenever the plugin build I was working with failed, I quickly set up another ant-based project for the time being. After a while I discovered the ant plugin for maven and abandoned the idea altogether. I haven't went back to ant ever since, and I don't plan to. The key to success was to keep things simple, sometimes sacrificing my own idea of "the way *I* like it" for the sake of simplicity. Over time I think It was the right decision and I stand by it. There is one more interesting thing for me. I feel the same way about control. I like to have it. But I feel quite the opposite about ant, maven and keeping dependencies in source repositories. I feel maven gives me *more* control (at least on things that matter the most to me). I say this because when .jars appear on source repositories, the following happens: 1) you can never know the state of those pesky jars, since most of the time the version number is trimmed from the filename, and sometimes the jars themselves are patched or augmented versions of the originals, so there is no way to upgrade them. 2) It takes forever to checkout (minor pain). 3) you have to go hunting for javadoc and sources for every dependency. So, IMHO, maven repositories are a huge gain, everything you need in a specific location BTW I've been recently converted to Wicket, too. GO WICKET!