fognl

Get off my lawn.

Saturday, October 20, 2007

Build-tool smackdown: Maven vs. Ant

Throughout history, things of a type with differing kinds have been going to war with each other. There's Ford vs. Chevy, Honda vs. Yamaha, boxers vs. briefs, Alien vs. Predator, and so on. Today's topic is the battle of the 21st century for Java build tools: Ant vs. Maven.

The difference between Ant and Maven is not really like the difference between Ford and Chevy, as noted above. It's more like the difference between a hand tool and a sophisticated futuristic robot.

Suppose you're building a birdhouse, and you have a bolt with a nut on it that needs to be tightened. Using Ant is like using a wrench. You reach into your toolbox, pull out the right wrench, put it on the nut, apply pressure, and tighten the nut. You have to know which way to push on the wrench, but that's something you learn almost instantly if you've never done it before. It makes sense, and having learned it, you don't have to think about it any more. And if there's a problem (say, the wrong-size wrench), you know it immediately.

Maven is more like a refrigerator-sized black box on casters that you wheel into the room, plug into a wall socket, and point toward the birdhouse. If the magic box "knows" what to do given the situation, it will be impressive: Lights on the box will blink, there will be an ominous low hum, the sun will darken, you'll hear thunder in the distance, and the nut and bolt will magically screw together. You'll also get a log file with charts in it to tell you how tight the nut was, before and after the operation, what the magic box did, and if there is anything wrong with the nut or bolt.

And all you have to do in order to get the robot to know where the nut and bolt are is to write a short description of them, and make sure they're in the right place. Very cool.

On the other hand, what happens if if the bolt and nut have left-hand threads? With Ant, you go through the same simple procedure but with a twist. With any intelligence at all, you'll notice that turning the nut to the right has the opposite effect you want, so you'll pull the other way on the wrench. Using the Maven approach, the nut will spin off and roll across the room, and fall into the floor drain. Then the robot will call the Police to report a robbery, and melt into a pool of slag on your garage floor.

I get the point. Maven is relatively sophisticated, and it can do a lot of things for you automatically. As long as you and your project both play by Maven's rules, you're in great shape. I recently did some work for a company where Maven is the required build tool. You ought to see it. People sit around for 10-15 minutes running massive Maven builds and looking bored, waiting for the builds to finish. Maven sure is doing a lot for them. I talked to the architecture team at the company about their choice of build tools. For them, the main reason for using Maven is for the reports it can generate to show to management. So essentially, in essence, programmer productivity has been de-prioritized in the name of some reports. Someone in management probably stated a desire to see these reports, but after looking at one of them (with their dependency lists and tables of test-coverage results), thought "oh, programmer stuff" and ignored them after that.

As a tool for developers, I'm not convinced of Maven's value. The dependency-management feature is great. But you buy a lot of complexity and rigidity to do along with it. What I like about Ant is that it's simple. Simple in the way that the C language is simple. Out of the box, it does almost nothing for you. But it's easy to learn how to use it, and it's easy to look at an Ant script and see what it's supposed to do, just like looking at C code. And over time, as you get better at using it, you learn how to make it do more and more things. My Ant environment, for example, runs off of a set of "master" scripts that contain a lot of functionality. When I write a build script for a specific component in my environment, it's typically very small and succinct compared to a Maven POM. I have a repository, I have standardized locations for resources, and I have automated builds and unit tests. Recently, I added the ability to put Groovy scripts in a build to do more difficult things. Now it's not only simple, but it's really pretty smart. And best of all, my build scripts typically run in about 2 seconds on my machine, vs. the 45-second thrash for the same goal performed by Maven.

It seems to be gaining momentum with the "Enterprise Actualization Patterns" crowd, so it's beneficial to know Maven. But for simple stuff where I have a choice, I'll stick with a simple wrench.