Building a Better Maven with Ant

It looks like the Ant folks are thinking of building a better Maven.

I see many developers adopt Maven because they want a build system able to provide common features with no effort. Most of them don't want to spend much time writing an Ant script, or have seen or heard that maintaining Ant build scripts is troublesome. So they choose to use Maven only because it's easy to use for common use cases: install, write a simple pom of a few lines or generate it using an archetype, and you're ready to compile, test and package your new project following the Maven standard structure. They also get dependency management for free, and with only a few more effort they have multi module builds, and some nice features like code analysis, coverage, and a set of report gathered in a web site. That's really nice and that's what I like about Maven.

But Maven suffers from a lack of flexibility and robustness IMHO. And later the same people who first adopted Maven because of its perceived ease of use become frustrated when they need to tweek the system to their own needs or don't understand how the release plugin work. Then some of them go back to Ant, first having to go through a sometimes painful road to describe their whole build system in xml, especially if they aren't Ant experts. Others try to use new build tools like raven, buildr or others.

I really like Ant, and think it is a very good basis for robust and flexible build systems. People with enough knowledge of Ant can write very good build systems, testable, maintainable and adaptable. But you need to get your hands dirty, and you need to get a good knowledge of some of the mechanisms which can make an Ant based build system manageable: import, scripts and scriptdef, macrodef, presetdef, and so on. [Read More]

What do you think - is this a good idea?

I agree that Maven has its warts, but I don't think it's that bad. I've also heard that Maven has been successfully implemented at large companyies like eBay, Intuit and E*Trade[1]. Is the "Maven sucks" meme largely something that exists in the blogosphere, but not in the real world?

I think the biggest benefit of Maven is dependency management. I think it makes your code more modular and easier to build. Rather than having a monolithic source-code tree that depends on itself being built in a certain order, you can have individual modules that pull dependencies from a central location. This can be done with Maven's Ant Tasks as well. I don't see a problem with building a better Maven with Ant, but to try and build a better Central Repository sounds like a nightmare to me. The current repository has been improved for years and is much better than it was a couple years ago. That being said, I would love to see somebody build a more accurate Central Repository. Ideally, it'd be done sometime next week. ;-)

[1] I could be wrong about these companies. If you're a developer at one of these companies, please confirm or deny. Any comments on Maven's success at these companies would be great as well.

Update: Speaking of Maven, there's an interesting comment on a Javalobby post I wrote:

With all the critical remarks the Maven project is receiving, wouldn't it be time for some Maven project lead to step up and explain the team's position? Or is it completely deaf to the sentiments? How many builds have to fail, how much more headaches are needed before others start their own version of Maven and do it the right way (like Don [Brown])?

Seems like an excellent question to me. Guys?

Posted in Java at Feb 11 2008, 02:07:12 PM MST 18 Comments
Comments:

I'd go one step further and say that the *only* reason to use Maven is dependency management. That's the killer feature that you can't live without. The project management model it provides is clunky and complex, but being able to call out specific versions in different profiles is something that's really powerful.

In other words, the repository is what matters, not the project model. Tools that operate with the existing repository, like raven and buildr, give you what you need to have without burdening you with what you don't.

I've done a number of highly complex builds, and I've come to the point several times where I wanted my builds to be in a real language like Ruby or Groovy (or even Java) instead of XML. I'm wary of trying to push Ant even further toward being a language -- that way lies only heartache and poor maintainability.

Posted by Ben on February 11, 2008 at 03:18 PM MST #

I think they should be cautious. Maven does work pretty well and it really sucks when you start a project and have to pick between two tools that both seem to do the same thing and are both equally popular. It's a lot easier when the only choice is maven. Perhaps they should contribute to the maven project itself.

I would argue that this is pretty similar to the birth of subversion, which in my opinion created a bunch of new problems while attempting to solve a couple of annoyances with CVS. It doesn't really seem worth it. I still prefer CVS simply because of the more solid eclipse integration, since it would otherwise be a toss-up.

Posted by Al on February 11, 2008 at 03:19 PM MST #

This sounds like Ant2, or Magic, or Centipede, or the early-early betas of Maven 1.0. It's not a bad idea for people who know and love Ant, and maybe the timing will be better for it now. The Ant community is certainly more receptive to it these days - I can remember some members being totally against any form of remote dependency management earlier on.

Maven's approach is just different, and some people love it and some hate it. I think the "strict confines" it imposes are one of its strengths, and it's the thing that appeals to large development shops where consistency across projects is important. And frankly, while I hear a lot of complaints about lack of flexibility, I don't think it's what really burns people.

I think that is simply inconsistent behaviour and bugs. And the Maven developers are completely familiar with what the issues are - most of them are on the roadmap. However, the core development community has been pretty slow moving for some time (for a number of reasons, but one is that 2.0 actually works for a lot of people once you get past the hurdles, and so there's fewer itches to scratch).

Maven needs more people like Don to just try things, submit patches, and be vocal to get it accepted (as much on the dev@ list as on blogs :). I personally welcome the work he put in, even it is a little hyped :) He's triggered some people taking action again on the dev@ lists.

Maven's users should be demanding incremental feature releases that include such things, instead of waiting for the next version which will "fix everything". Normal caveat applies that in open source, often demanding something as a user leads to the previous paragraph :)

Posted by Brett Porter on February 11, 2008 at 04:16 PM MST #

EJB 2 : EJB 3 :: Maven 2 : ???

I'm waiting for the EJB 3-ish version of Maven. Something that is less heavy-handed. It may or may not come from the Maven people. For a while I thought it was (Apache) Ivy, but I'm feeling like they love configurability more than simplicity. They're making strides though.

Posted by Paul on February 11, 2008 at 04:26 PM MST #

You can absolutely build pretty cool stuff with Ant. But I would also say that you can build really cool stuff with Ant + Ivy. Having done this before, you can cover many useful Maven features with just a few hundred lines of XML and two days of tinkering.

I am doing builds with 50 or so of my own modules and hundreds of dependencies with this type of setup. Most of my module builds only require a few lines of XML and the Ivy file (POM). Ivy will then figure out the build tree, and off you go firing your Ant module builds in the right order. Ivy will also take care of grabbing all my dependencies that I need.

You can ask why spend two days tinkering when you could be done in minutes. I guess the benefit is that I am in full control and I can modify the build easily any way I want. I also do not have to worry about many of the problems that might show up with Maven.

I definitely do not see people go building things like these instead of using Maven, but if you can, and you will get a lift out of it, then why not. If there is a standard system, then it really is a question of which one is better. I think Maven could use a little competition in this space. At least people would have two reasonable choices.

Posted by Tero on February 11, 2008 at 05:02 PM MST #

You can absolutely build pretty cool stuff with Ant. But I would also say that you can build really cool stuff with Ant + Ivy. Having done this before, you can cover many useful Maven features with just a few hundred lines of XML and two days of tinkering.
Are you serious?? "Just" a few hundred lines of XML?!?! While I'm made painfully aware of Maven's warts every day, I keep reminding myself that I'm still *way* better off than I was in the days of "several hundred line" ant scripts that had been "tinkered" together.

Posted by Peter on February 11, 2008 at 05:14 PM MST #

Are you serious?? "Just" a few hundred lines of XML?!?! While I'm made painfully aware of Maven's warts every day, I keep reminding myself that I'm still *way* better off than I was in the days of "several hundred line" ant scripts that had been "tinkered" together.
We also run an ant & ivy setup. That may sound like a lot of XML but we basically wrote our build file once and each project reused this by importing the standard build using the <import> task. Total build file size for new projects is then a grand total of about 5 lines. If needed each project/module can add it's own custom stuff fairly easily.

Posted by Glen on February 11, 2008 at 06:27 PM MST #

I am sorry I was not clear. That several hundred lines of XML were reused with Ant imports in all the projects (= a lot of them). By doing this, I actually reduced the build file sizes over 95% from what they were before.

The actual XML you write to build the modules is often less than 10 lines of Ant XML. And even when you want to customize the builds, it is often easy just by using task injection points in strategic locations, or by overriding the tasks that you need. You can also heavily use macros for most common things so you can do one liners for what used to take 30.

To put this in contrast with Maven that took years to develop - two days of tinkering to get similar benefits is pretty good IMHO. Any average guy can do it with Ant + Ivy and be in full control, and the stuff just builds every freaking time. No fuss.

To be fair, these builds require public maven repos but they are just not a viable choice for any serious builds (=too flaky). Therefore I use local staging repos and individual repos for each developer to do their isolated builds. I can then fix the borken POMs in my staging repos.

Posted by Tero on February 11, 2008 at 10:52 PM MST #

Personally, I think Maven Rocks!

My biggest problem with Maven is that not everybody uses it. If every project had a decent pom and artifacts properly organized on Ibiblio, it would make using Maven MUCH easier...

Besides dependency management, the sites are key. The fact that I can define static code analysis checks and reports, test coverage reports, etc. I know I can do all of this with Ant, but I prefer the Maven framework.

Once developers see what Maven can really do, they get hooked.

Posted by Anthony on February 12, 2008 at 12:10 AM MST #

The problem I see with Maven is that it has an "object" model for a project. All the life-cycle stuff is an overkill for a build system. The builds have always been "procedural": a sequence of project specific steps/tasks that need to be executed.

Posted by some guy on February 12, 2008 at 03:27 AM MST #

I think the object model is great. We compile jaxb stuff, build wars, jars, rars etc. We have a common root pom project shared by all other projects where we define how and where to deploy, common versions of some artifacts and more. The root pom also contains all eclipse settings, formatting rules. We setup eclipse to compile with AspectJ for some projects. What most people don't have, but really should have, is a local maven repository and proxy. We run Artifactory. Maven rules! :-)

Posted by Magnus Heino on February 12, 2008 at 03:47 AM MST #

I was using Maven at my company to build one of our smaller products. Release engineering, however, hated it. While the dependency management seems the most helpful part of Maven, it's been the most problematic because-- (1) it requires an active network connection and repositories to be online, (2) you can't trust external repositories, so you now must maintain and populate your own repository, and (3) transitive dependencies must be very carefully managed to make sure your product doesn't unknowingly become dependent on any "viral" OSS software. In our experience, #1 has caused builds to fail despite perfectly good code, #2 has been fairly cumbersome to maintain, and #3 has kept the lawyers nervous. I like Maven a lot, but in the end, the extra day spent on writing a good ANT script and putting the dependencies in source control has proven to be worth it over the long run-- we now have a fully self-contained build that we know is guaranteed repeatable, even many years down the road. That puts my mind at ease.

Posted by Chris M on February 12, 2008 at 09:56 AM MST #

Mavens great when it works - but when it doesn't it can make you tear your hair out. From an OSS PoV I'm really relieved when I go to a project for the first time an theres a maven build - make it very easy to get started playing with that project. The other side of the coin is when you're maintaining a maven build on an OSS project - thats when you get to pull your hair out - luckily I haven't got much.

Posted by Niall on February 12, 2008 at 11:32 AM MST #

Chris M: You need a Maven proxy and a own repository. Look at Artifactory. It will solve all of those problems.

It's also really easy to write your own Maven plugins. Just write a plugin that verifies that no "unwanted" artifacts are included.

Posted by Magnus Heino on February 12, 2008 at 12:30 PM MST #

Here's a quite interesting post from Howard Lewis Ship on similar topic:

http://tapestryjava.blogspot.com/2007/11/maven-wont-get-fooled-again.html

I personally would prefer a mix of Gant expressiveness (Ant but with Groovy instead of XML) plus a kind of "project templates". Dependency management should be optional imho, because quite many projects want a closed/frozen environment.

Posted by Victor on February 12, 2008 at 05:40 PM MST #

I'm working now with a group of people deploying Java and .NET applications. And, for the Java deployers, I don't think they can live without Maven. I can make some custom applications and then train folks to use Maven to copy these things and quickly do some complicated security implementations and JBoss deployments. Maven removes the dependency, classpath, IDE nightmares. I can show newbie Java folks how to accomplish big things by copying the dance of others. These administrators aren't developers but they may learn to write servlet filters or tweak LDAP utilities, etc. and Maven can be set up for them and they will learn quicker.

Posted by David Whitehurst on February 19, 2008 at 05:52 PM MST #

I think the gradle project got things right:

1. you can easily use any ant task
2. there's a model for defining dependencies, that uses ivy
3. plugins can provide model objects a-la maven's pom. they can also provide standard targets (so to build a standard jar, your build file is just 'usePlugin("java")'.
4. you can rewrite any target
5. each module has an object representing it. then, in the root build file (or any module's build file) you can manipulate these objects, rather than needing to create a build file in each (even if it is just 5 lines). but, if you do have a build file, it inherits methods & variables from its parent (the one that defined to use it).
6. build scripts are groovy, so you have methods, control structures etc.
7. cross module target dependencies. so you can generate sources in module M1, then compile module M2, then compile module M1.

Posted by Ittay on June 10, 2008 at 02:40 AM MDT #

I will NEVER use Maven. A project that uses jars should just keep them all in one directory. If it's a client application the jars need to be named in a manifest anyway (can't change the names). The jars shouldn't be compressed since when the exe is built (or whatever other native format on your OS of choice) compression will be applied anyway. If your project links to other projects, these other projects should have periodic jar releases (just like the jars you get from jakarta etc..). Circular dependencies means you screwed up somewhere. There simply shouldn't be any. Adding a monolithic undocumented XML based overly complex overly engineered tool is not the solution to bad designs. The problem with Maven is that it looks o.k. to a lot of "pretty good" developers. This causes the proliferation of a bad tool. It's kind of like STP fuel additives.

Posted by waiting_for_maven_to_die on August 07, 2008 at 04:21 AM MDT #

Post a Comment:
  • HTML Syntax: Allowed