Continuing the Java build systems discussion, today I want to focus on Maven, what it does well and what it does that frustrates.Â We’ll get a little taste of the minimum expectations for a new build system as well.Â Note:Â this page may be subject to edits, as I come across more pros & cons of Maven.
What Maven does right
Maven teaches us several important things about what we need from a build system.
- Convention over configuration. Maven strongly encourages developers to put source files, resources, tests, and project metadata in standard locations.Â Maven make life very difficult for anyone deviating from the norms.Â In general, this is good, helps teamwork and collaboration, and helps for picking up a project cold.
- Defaults just work. Similar to the last entry, if you follow maven standards, then it works fine and has a reasonable assumption of defaults.
- Dependency Management. Probably the single best feature of Maven and modern build tools.Â This allows a developer to specify requirements for a project without having to directly specify the physical location of those library dependencies.Â This frees the build system to resolve from the network, automatically check for updates, and manage multiple versions of libraries.
- Plugins.Â Easy extensibility is key to Maven.Â In fact, most of its internals actually exist as plugins, from compilation to Ant support to deployment.Â The ability to add new, custom behavior and have it tie into your builds is fantastic.
What Maven does wrong
There are some pretty big gotchas in Maven.Â Nothing insurmountable, but frustrating nonetheless.Â And before you say “It’s open source, fix it yourself!” know that it is not that simple.Â There may be resistance to a certain change, for example, from “the establishment” or some issues and Maven’s solutions are fundamentally tricky.
- Outside the ordinary is very hard. Doing anything beyond the standard use cases requires an arcane knowledge of plugins.Â All of a sudden, Maven’s configuration-based approach falls down, and things become easier to do in code — ie, you have to write a plugin.Â But don’t think you can use the nifty ant-scripted mojos for that plugin– for example, for compilation, there isn’t a standard way to get the classpath into the ant script.
- Dependency Management. Yep, the same benefit is a detriment.Â Or, at the very least, Maven’s handling of it.Â Several things fall in here.Â The ones I can recall are:
- Transitive dependencies prove very tricky and make for lots of classloading troubles.Â Adding a single dependency to a POM can really change the entire dependency graph ofÂ a project.
- There is no way to simply say “I want the latest of library XX”.Â On the one hand, Maven makes sense here; you should usually know exactly which version of software you are building against.Â But there are cases, for example, due to a lack of maturity, where having to know that version number is just an annoyance.Â Ivy apparently has an intermediate option here, where you can specify latest, but when a build happens, it records what that version was.
- Long-standing bugs. Maven suffers a bit from what other mature open-source products hit upon.Â Whether it is loss of momentum for something that works well enough or that too many are depending on the quirks, there are lots of oddities and issues left in core plugins.Â A perfect example is maven-antrun-plugin, which only sets its classpath once per maven run, regardless of how many POMs reference it.
- Documentation bugs. Some of the Maven docs are a bit light on details.Â Part of it may be Maven’s built-in site creation, which leads to some sites that have lots of links but are pretty information-sparse.Â Other times, many common scenarios are presented, but some of the edge cases are glossed over.Â Related:Â looking for a list of available Maven properties for use in your POM is tricky because of Maven’s dynamic nature.Â But a simple guide describing common ones and how to construct others would be great.
Generally, what Maven teaches us is that you need to fully embrace Maven to get the full benefit of Maven.Â Once you get the hang of the Maven way, things go much more smoothly.Â That is not unexpected, but it is uncomfortable.Â But there are times where you have to fight — deploying to multiple load-balanced servers, for example, and you end up with some nasty scripts and configuration on top of a previously elegant solution.
The important thing is, though, that Maven does work.Â It’s not too much of a bear to get started with, has great defaults, and it has some compelling solutions to annoying problems.
So, can Maven be fixed?Â Should it be fixed, or should a build system start from scratch?Â More on that next time.