06 · Maven from first build to release / LESSON 25 OF 102
Multi-module projects and dependency direction
A reactor builds related modules in dependency order while each module remains an artifact.
Before this lesson: Surefire, Failsafe, and test naming
Understand the topic
An aggregator lists modules and usually has pom packaging. A parent provides inherited configuration; one POM may be both, but aggregation and inheritance are different concepts. Declare explicit inter-module dependencies rather than relying on source-folder visibility.
Keep domain code independent of web adapters. Cyclic module dependencies prevent a meaningful build order and usually reveal confused responsibility. Use -pl to select a module and -am to also build its required reactor modules.
EXAMPLE · SHELL
Terminal
./mvnw -pl task-api -am verifyWhat to expect
From an aggregator containing task-domain and task-api, Maven also builds required reactor dependencies of task-api.
YOUR TURN
Put it into practice
- 01Split task-domain and task-api into two modules.
- 02Make the API depend on domain, then intentionally add the reverse dependency to inspect the cycle error.
- 03Verify: The final reactor is acyclic and the domain module has no servlet or controller dependency.
Pass a quiz or complete a lab to check today’s streak. Each lesson counts once per day, including when you review it later.
UNDER THE HOOD
Build the mental model
A reactor builds related modules in dependency order while each module remains an artifact.
- 01An aggregator lists modules and usually has pom packaging. A parent provides inherited configuration; one POM may be both, but aggregation and inheritance are different concepts. Declare explicit inter-module dependencies rather than relying on source-folder visibility.
- 02Keep domain code independent of web adapters. Cyclic module dependencies prevent a meaningful build order and usually reveal confused responsibility. Use -pl to select a module and -am to also build its required reactor modules.
- 03Trace the example: From an aggregator containing task-domain and task-api, Maven also builds required reactor dependencies of task-api.
A mistake worth avoiding
A module works only after manually installing another module.
DEBUGGING ROOM
Something broke. Where do you look?
A module works only after manually installing another module.
Before revealing the diagnosis, write down your first investigation step.
CHECK YOUR UNDERSTANDING
Does listing a module automatically make its classes available to every sibling?
BUILD IT YOURSELF
Split task-domain and task-api into two modules.
- 1.Split task-domain and task-api into two modules.
- 2.Make the API depend on domain, then intentionally add the reverse dependency to inspect the cycle error.
- 3.Reproduce this failure, then repair it: A module works only after manually installing another module.
Acceptance checklist
Lab completion is your self-report. Knowledge checks do not certify project quality.
RETRIEVE IT FROM MEMORY
Does listing a module automatically make its classes available to every sibling?
Revisit this lesson in three days after a successful check or lab.
Ready for the next step?
The final reactor is acyclic and the domain module has no servlet or controller dependency.
Reading is separate from passing a knowledge check or completing a lab.