Quick revision
The short answer
The reactor is the part of Maven that collects all the modules of a multi-module build, works out how they depend on each other, and builds them in dependency order, not in the order they are listed. The option -pl picks the modules to build, -am also builds the modules they depend on, -amd also builds the modules that depend on them, and -rf resumes a failed build from a given module. -T builds independent modules in parallel.
What to remember
In this answer, we saw that the reactor collects all modules, builds a dependency graph and sorts it so each module is built after what it needs, regardless of declaration order. We used -pl to pick modules, -am to add their dependencies, -amd to add their dependents, -rf to resume after a failure and -T to build independent modules in parallel. We also saw that the modules list (aggregation) and the parent element (inheritance) are separate ideas that often share one POM.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The reactor is the part of Maven that collects all the modules of a multi-module build, works out how they depend on each other, and builds them in dependency order, not in the order they are listed. The option -pl picks the modules to build, -am also builds the modules they depend on, -amd also builds the modules that depend on them, and -rf resumes a failed build from a given module. -T builds independent modules in parallel.
Why this question is asked
Once a project has more than a handful of modules, building everything for every change becomes slow, and running a single module on its own often fails because its sibling modules are not built. Knowing how the reactor orders the build, and how to ask it for just the part we need, saves minutes on every run. Interviewers ask this because it shows whether we have actually worked in a multi-module codebase. In this answer, we will recap what a multi-module project is, see how the reactor computes the build order, try each of the selection options on a small example, and clear up the difference between a parent POM and an aggregator POM.
1A Quick Recap of Multi-Module Projects
A multi-module project is one Maven build made of several modules, each with its own pom.xml and its own artifact. A top-level POM lists them in a modules section. When we run mvn verify in the top directory, Maven builds all of them in one go.
The component that does this is called the reactor. It reads the top POM, follows the modules list (and the modules lists of those modules, if they have their own), and ends up with the full set of projects that take part in this build. For our examples we will use a small shop project with four modules: common, orders, payments and app, where orders and payments depend on common, and app depends on both orders and payments.
2How the Reactor Decides the Build Order
The reactor does not build modules in the order of the modules list. Instead it looks at the relationships between them: a dependency on another module, a parent that is another module, or a plugin or extension built by another module. From these it builds a dependency graph and sorts it topologically, which means every module comes after everything it needs.
So even though app is listed first, Maven builds common first, then orders and payments, and app last. The reason is obvious once we say it: app's compile step needs the classes of orders and payments, which need common. If the graph has a cycle, for example common depending on app, the reactor refuses to build and reports the cycle, because no valid order exists.
- shopaggregator, packaging pom
- commonno module dependencies, built first
- orders and paymentsboth need common; independent of each other
- appneeds orders and payments, built last
4 layers, from the top down. Step through them one at a time.
Modules in the same layer can be built in parallel with -T.
Notice that orders and payments do not depend on each other. Their relative order is just a tie-break, and that independence is what lets a parallel build run them at the same time.
3Choosing Part of the Build With -pl, -am and -amd
The option -pl, short for --projects, selects which modules to build by directory or by artifactId. On its own it builds only those modules, and expects the others to be available already in the local repository.
The option -am, short for --also-make, adds every module that the selected ones depend on. We use it when we want to work on one module and have Maven build exactly what it needs, nothing more. The option -amd, short for --also-make-dependents, adds every module that depends on the selected ones. We use it after changing a shared module, to check that nothing downstream broke.
Notice the difference between the first two lines. Without -am, Maven uses whatever version of common is in the local repository, which may be a stale build from last week. That is a common source of 'it works on my machine' confusion, and -am avoids it.
4Resuming a Failed Build With -rf
In a long build, a failure near the end is painful if we have to start again from the beginning. The option -rf, short for --resume-from, starts the reactor at the named module and continues in the normal order from there. Maven even prints the exact command to use when a build fails.
There is a catch: modules before the resume point are not rebuilt, so payments uses the copy of common from the local repository. If we changed common in the meantime, we should not resume; we should build again with -am or from the top. Maven 4 adds a -r (--resume) option that remembers where the last build failed, so we do not even need to type the module name.
5Building Independent Modules in Parallel With -T
Because the reactor knows which modules are independent, it can build them at the same time. The option -T sets the number of threads, either a fixed number or a multiple of the CPU cores.
In our example, orders and payments are built at the same time once common is done. The saving grows with the width of the graph: a build with many independent modules gains a lot, a build that is one long chain gains almost nothing. Plugins must be thread-safe for this; Maven prints a warning for plugins not marked as such.
6Parent and Aggregator Are Not the Same Thing
Two different features often live in the same top-level POM, which is why they get confused. Aggregation is the modules list: it tells the reactor which modules to build together. Inheritance is the parent element in a child POM: it gives the child the parent's properties, dependencyManagement and plugin configuration.
In our shop project the top POM is both, but they can be separate. A company's corporate parent POM is released on its own and is the parent of hundreds of projects without listing any of them as modules. And an aggregator POM can list modules that each have a different parent. The reactor only cares about aggregation for deciding what to build; inheritance affects what each module's configuration looks like.
7Follow-up questions
Why might a module build fine in the full build but fail with -pl alone?
Because without -am, Maven does not build the sibling modules it depends on and instead resolves them from the local repository. If they have never been installed, the build fails to find them; if an old version is installed, the module compiles against old code. Adding -am makes Maven build the dependencies in the same reactor, which matches what the full build does.
How do you build only the modules affected by a change on a pull request?
We map the changed file paths to the modules that contain them, then run mvn -pl with that list plus -amd, so the changed modules and everything that depends on them are built and tested. Adding -am as well makes sure their own dependencies are built in the same reactor rather than taken from a stale local repository.
8Conclusion
In this answer, we saw that the reactor collects all modules, builds a dependency graph and sorts it so each module is built after what it needs, regardless of declaration order. We used -pl to pick modules, -am to add their dependencies, -amd to add their dependents, -rf to resume after a failure and -T to build independent modules in parallel. We also saw that the modules list (aggregation) and the parent element (inheritance) are separate ideas that often share one POM.
Open with
The reactor is the part of Maven that handles multi-module builds. It reads the top POM's modules list, collects all the modules, and builds a graph of how they depend on each other, through dependencies, parents and plugins.
Then, if they want more
Then it sorts that graph topologically, so every module is built after the modules it needs. The order of the modules list only breaks ties; if the graph has a cycle, the build fails. For building part of the project, -pl selects modules by directory or artifactId.
On its own it builds only those and takes everything else from the local repository, which can be stale. Adding -am, also make, builds the modules they depend on as well; -amd, also make dependents, builds the modules that depend on them, which is what I use after changing a shared module or on a pull request.
If a long build fails in the middle, -rf with the module name resumes from there, and Maven even prints that command, though I would not resume if I changed an earlier module. And -T, for example -T 1C, builds independent modules in parallel.
One more thing that often gets mixed up: the modules list is aggregation, the parent element is inheritance. They are often the same POM, but a corporate parent, for example, is inherited by many projects without aggregating any of them.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Maven guides
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "In a Maven multi-module project, what is the reactor and how does it decide build order?...": https://scrivio-interview-library.netlify.app/java/maven/8e8de5e0ec/