I’m enjoying Maven


Like most Java developers, I have an opinion about Apache Maven. So far, I really like it. I wouldn’t try to build modular software without it and, even with its faults, I hope something very like it becomes a de facto standard.

Maven invites you to define your project as a named, versioned component that depends on other components. Maven assumes that your project follows a set of conventions for layout and, in return, you get the essential tasks: transitive dependencies are brought in and the compile time, test and runtime components are kept distinct. It will generate a unit test report, with test coverage, along with Javadoc and a packaged jar. There’s no rocket science in there, but copy-and-pasted Ant scripting goes away.

Other tasks use the dependencies; building up a distribution with all the other jars is simple. Update to more recent versions, run it again. Metadata can be used to track license consistency for a large project.

For me, the motivating feature is componentisation. It becomes very easy to split a large project into modules, and to make sure the dependencies are correct and consistent. It’s easy to build the whole thing from source or to take a module and build it against snapshots of a larger more stable framework. I feel a lot more comfortable with a clean, repeatable from-source build, and Maven really helps with that.

Of course, if you’ve used Maven you’ll have a few criticisms. If you’ve used it even semi-seriously, that’ll be a long list. Jason van Zyl mentions the path-paving model of development, which seems very appropriate in this case. I feel confident that the problems I see are fixable without a fundamental change of model. But yes, if you’re evangelising, don’t waste time claiming it’s perfect. Almost all the criticism you’ll hear is legitimate but not a deal-breaker. People are very attached to putting their source in a particular directory, just like some people still steer clear of Python for its white space.

Maven creates a fairly large infrastructure burden if it’s embraced fully for larger commercial deployments. Sonatype’s business model seems to be based around increasing demand for that infrastructure and then selling a solution for it. I like that, pace the usual suspicion about conflicts of interest between the free and commercial products from a company (their position is well stated). There’s some healthy debate over the relative merits of the repository implementations. All I can say is; Nexus worked well enough for me that I didn’t go looking for an alternative. Well done on the OOBE.

Maven, Ivy, OSGi and Project Jigsaw all touch on similar territory, and there are many projects to blend one with another. An open-minded approach to see what works and share the best ideas can only lead to a better product.

(Music: Kyuss, “Whitewater”)
(More from this year, or the front page? [K])