Maven Multi Module benefits over simple dependency

I think you are correct in that most project that use multi modules, actually don't need them.

At where I work we use multimodule projects (and I think that for a good reason). We have something similar to a service oriented architecture, so each application

  • A client module
  • An interface module (which has shared objects between the client and implementation)
  • an implementation module
  • a war module

I agree that putting that implementation and war module in the same actual module would be ok, but the (arguably) benefit of this is that is very clear division between the classes that solve the problem and how the application communicates with the external world.

In previous projects that involved just a web application, I've tried to put everything in the same module, as it made testing easier, given the modules I was using.


Multi modules can help you with re-use your code. It's one of the best benefits you'll feel in work.

Imagine if you have 3 web projects with a security layer, You'll have to copy paste your code 3 times and trying connect it with each project.

But what if you create a security module a project with a specific job. It'll be easy to use it by injecting it to your app and then boom it works.

Also as mentioned in @ben75's answer the one maven build command and the correct order of building all your used jars. You'll think no more about which depends on another.


Here's a real life case.

I have a multi-module project (and to your rant... I haven't seen any complications with it.) The end result is a webapp but I have different modules for api, impl, and webapp.

12 months after creating the project I find that I have to integrate with Amazon S3 using a stand-alone process run from a jar. I add a new module which depends on api/impl and write my code for the integration in the new module. I use the assembly plugin (or something like it) to create a runnable jar and now I have a war I can deploy in tomcat and a process I can deploy on another server. I have no web classes in my S3 integration process and I have no Amazon dependencies in my webapp but I can share all the stuff in api and impl.

3 months after that we decide to create a REST webapp. We want to do it as a separate app instead of just new URL mappings in the existing webapp. Simple. One more module, another webapp created as the result of the maven build with no special tinkering. Business logic is shared easily between webapp and rest-webapp and I can deploy them as needed.


The major benefit of multi modules are

  • one single maven command to build all your modules at once.
  • and the most important : maven take care of the build order for you.
  • configuring your CI-server is also very easy: one single jenkins job to build everything.

I already worked in a project with about 30 submodules. Sometimes, you need to change something in more than module, and running one single command and being sure that everything that need to be compiled is compiled in the correct order is a must.

EDIT

Why 30 submodules ?

Huge framework with lot's a features, lot's of developers, separation of features on a module base. It's a real life use case and the separation of the code into module was really meaningful.