When should a maven multimode project be used?

I am very new to Maven. Maybe this is the reason for this question :)

Today I tried to download a project called Sonar Runner and just see how it works. It was a rather strange experience for me, because this project has 4 submodules:

  • Sonar Runner - API
  • Sonar Runner - Package
  • Sonar Runner - Distribution
  • Sonar Runner - Deployment

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

It makes me wonder why it is so beautiful. I know that you donโ€™t know what their reasons are. But I'm curious what the reasons may be.

Until now, I thought that the size of the project is the reason or the individual teams working in different parts of the project.

But when the project has 40 java files, I think that size is not the reason.

What do I get when I use a multi-module project instead of one large project?

I tried to find the answer on Google, but no luck.

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

But still with a project having 40 java files. Dividing it into 4 submodules seems to me just ridiculous.

Are there any other benefits?

+5
source share
1 answer

I almost always do multi-module Maven projects - even if I hack only an open source experiment.

There are many reasons for creating multi-module projects:

  • Different parts of the code apply to different environments. You may want to separate the APIs and implementation tools or compile time from the things you need at runtime.
  • It makes sense to embed different functional components in different modules.
  • Individual modules may have their own roadmap. For example, the API can remain very stable for a long time, but the implementation will be updated frequently.
  • Even if you are running a project with one JAR, you may need a separate module with test tools or separate samples / demos / tests.
  • Even if you donโ€™t need everything, even with one JAR of it, it is often useful to create a parent pom and a child jar module. And move the organization element to the parent pom .
  • You may need to split one module into several if you have a circular dependency. If part A depends on B and B depends on part A , you may need to divide A into A1 and A2 .
  • I often prefer not to mix manually written and generated code in one module.

And probably a lot more.

These reasons are so great that over the years I prefer to start by installing parent / child from the beginning. I canโ€™t remember a single project in which I was involved, which will remain one module.

Even splitting a project with two files in 2 modules does not sound funny to me if there is a reason for this.

+5
source

Source: https://habr.com/ru/post/1207894/


All Articles