recently i have spent some time to break a monolith project into multiple modules within a single monorepo.
it was a huge codebase with several different projects commingled together into a same git repo. after the change, it now break into different modules, literally several microservies in a monorepo.
there are several benefits with this change. the key one is, instead of sharing all code together in each project, it will now build its own module separately with only needed code of concern, and only needed depencencies, (hence with a faster build time, smaller package, and separate of concerns). At the same time, the common/core code can still be shared/maintained across, vs the breaking updates/compatibility issue with normally package/jar sharing.
Here is how the project looks like before and after
before: monolith project
One of the key change is with the maven multi modules.
where the parent pom specify the modules to include (for both compile and runtime packaging), with itself being a pom packaging.
Then for each microservice/module, refer back to its parent module, and include the shared/core module if needed.
then for IDE and CI/CD, build from parent module would have sub modules executed (packaged for example, if run
in order to build a single module alone, this can be instead achieved by running `mvn $goal (package) -pl moduleA -am`. this could be triggered either locally, for example through a filewatcher for hot reload, or CI/CD for specific branches or MR.