zimi
zimi

Reputation: 1596

When should I use multi module maven project?

I'm pretty newbie in Maven. Maybe that's is reason of this question :)

Today I tried to download project called Sonar Runner and just see how it's working. It was pretty strange experience for me because this project has 4 submodules:

They have respectively: 17, 2, 8 and 13 java files.

It makes me wonder why it's so fine grained. I know that you don't know what was their reasons. But I'm curious what reasons can be.

Until now I thought that size of project is a reason or separate teams working on diffrent parts of project.

But when project has 40 java files I guess size is not the reason.

What I get when I use multi-module project instead of one big project?

I tried to find out the answer in Google but with no luck.

EDIT: I found this one: Is there any benefit in using Maven Multimodule when working in a small application?

But still with project having 40 java files. Splitting it into 4 submodules seems just ridiculous for me.

Are there any other benefits?

Upvotes: 9

Views: 3512

Answers (1)

lexicore
lexicore

Reputation: 43661

I'm almost always do multi-module Maven projects - even if I'm hacking some open-source experiment alone.

There many reasons to do multi-module projects:

  • Different parts of the code are relevant for different environments. You may want to separate API and implementation or compile-time tools from things you need in a runtime.
  • Makes sense putting different functional components in different modules.
  • Separate modules may have their own version roadmap. For instance, an API may stay very stable over a long time but the implementation will be updated often.
  • Even if you're doing a single-JAR project, you may need a separate module with test tools or separate samples/demos/tests.
  • Even if you don't need all, even with single-JAR of this it is often useful to make a parent pom and a child jar module. And move the organisational stuff to the parent pom.
  • You may need to split one module into several if you have a circular dependency. If part of A depends on B and B depends on a part of A, you may need to split A in A1 and A2.
  • I often prefer not to mix manually written and generated code in one module.

And probably much more.

These reasons are so many so since years already I prefer to start with the parent/child setup from the very start. I can't recall a single project I was involved in, which would stay single-module.

Even splitting 2-file project in 2 modules does not sound ridiculos to me, if there are reasons for this.

Upvotes: 10

Related Questions