03:35:25 pm on December 6, 2010 |
While I’m a massive proponent of Maven, I’m sceptical of the benefits of nested modules. I think they encourage a lot of bad coding and build practices so, when I see people using them, I shudder. Here are my 4 reasons why:
- M2Eclipse does not support them: Not the best reason, which is why I’m listing it first (save the best for last). Given that a lot of people use Maven through M2Eclipse, I think it is a significant obstacle for day-to-day development. Actually, M2Eclipse used to support nested modules but removed support for various reasons.
- Brittleness: One of the nice features of Maven is the ability to loosely couple project dependencies. You don’t care where dependencies live, whether it’s in your Eclipse workspace, a local or remote repository, or some other kind of container altogether. But nested modules use sub-folders so everything has to sit in specific, relative folder locations. This creates a tight coupling between modules. Suddenly you have to care where your modules sit, making your project brittle.
- Time consuming: There is also a development overhead incurred by having to check out, test and build a bunch of other modules when you’re only making changes to a single module. Doesn’t sound like much but it all adds up, draining development time, consuming system resources. We’ve all sat there taping our fingers while our continuous integration server builds for a release.
- Encourages monolithic projects and discourages code re-use. Normally Maven encourages you to separate your components into individual projects. If your project needs to use a piece of code from another project, you simply re-factor that shared code into a new project and add it as a dependency to both. Once you’ve separated code into a new dependency it’s an independent blob, with it’s own life-cycle, and it’s clearly separated from other chunks of code. But with nested modules, different modules can all to easily cross-breed, becoming tightly coupled to the project code base and life-cycle, making it harder to re-use them in other projects.
We all remember the problems with monolithic, Ant-based build scripts: brittle, difficult to integrate with other build tools, and slow. I don’t think nested modules are really much better. In fact, I would argue that using nested modules as described here is a Maven anti pattern.
That said, I’m open to discussion, so if you have seen benefits with nested modules comment here and let me know.Advertisements