Scrivio Interview library
ScenarioIntermediate6 min read · updated 12 November 2026

A developer says 'mvn install' is required before every build of your multi-module project because modules cannot see each other's changes. What is going on and how would you fix the workflow?

Inside one build of the whole project, Maven's reactor resolves sibling modules from the current build, so mvn verify or mvn package at the root is enough and nothing needs installing. The developer's problem appears when they build a single module on its own: Maven then resolves the siblings from the local repository in ~/.m2, which holds whatever was last installed and may be stale. The fix is to build from the root with -pl module -am, which builds the module plus the modules it depends on in one reactor, and to keep install out of the everyday workflow and deploy only from the release or main pipeline.

Why this question is asked

Many teams carry habits from an old problem long after the problem is gone. Running mvn install before every build is one of them: it slows everyone down and, worse, makes builds depend on whatever happens to sit in each developer's local repository. Interviewers ask this scenario because the explanation shows whether we understand how Maven resolves dependencies between modules. In this answer, we will recap the reactor, see exactly when modules see stale code, fix the workflow with the right command-line options, look at why installing from many branches is harmful, and set the CI rules.

1A Quick Recap of the Reactor

A multi-module project has a parent POM at the root whose modules element lists the child modules, for example api, service and app. When we run Maven at the root, it reads all the modules, works out which depends on which, and sorts them so that every module is built after the modules it needs. This mechanism is called the reactor.

The important part is resolution. When the service module depends on api, and api is part of the same reactor build, Maven does not look for api in a repository. It uses the output of the api module from this build: its jar, or for earlier phases its target/classes folder. So changes in api are visible to service in the same run, without any install.

2When Modules See Stale Code

The trouble starts when the developer runs Maven inside one module's folder, for example cd service then mvn test. Now the reactor contains only service. Its dependency on api cannot come from the build, so Maven looks in the local repository, ~/.m2/repository, the cache on the developer's machine where install puts artifacts. If the developer changed api an hour ago and did not install it, service compiles against the old api jar. A method added to api is missing, and the build fails, or worse, compiles against old behaviour and the tests pass for the wrong reason.

So the developer learned that installing first fixes it, and generalised that into installing before every build. The real cause was building a module outside its reactor.

Step throughBuilding one module alone resolves the sibling from ~/.m2
DeveloperMaven in service/Local repo ~/.m2api source
api changed: new method added, not installed
mvn test inside service/
resolve api 1.4.0-SNAPSHOT
api jar installed yesterday
cannot find symbol: the new method

5 messages in order. Play them, or step through them one at a time.

From the root, the reactor would have used api's current build output instead.

3Fixing the Workflow With -pl and -am

The developer usually builds one module because building everything is slow. Maven has options for exactly that, run from the root. -pl, or --projects, selects the modules to build. -am, or --also-make, adds the modules they depend on. Together they build the selected module and its upstream siblings in one reactor, so the siblings are resolved from the build, not from ~/.m2.

Java
# from the project root
mvn -pl service -am test # builds api, then service; service sees api's current code
mvn -pl service -amd verify # builds service and every module that depends on it (also-make-dependents)
mvn verify # the whole project, nothing installed
# what the team was doing
mvn install && cd service && mvn test # slower, and depends on what ~/.m2 contains

-amd, also-make-dependents, is the reverse: after changing api, it builds api and everything that uses it, which is how we check that a change did not break downstream modules. IDEs that import the Maven project also resolve modules from the workspace, so most daily work there needs no install either. Newer Maven versions improve reactor handling further, so check the release notes of the version the team uses.

4Why Installing From Many Branches Hurts

Snapshot versions such as 1.4.0-SNAPSHOT are not unique to a branch. A developer who installs api from feature branch A, then switches to branch B and builds service alone, compiles against branch A's api. The build passes or fails depending on what was installed last, which is the kind of problem that wastes an afternoon.

It also hides version mistakes. If someone forgot to update a module's version, or a module depends on a sibling version that no longer exists in the source, the stale jar in ~/.m2 satisfies the dependency on that developer's machine, and the build only breaks on a clean CI agent or for a new colleague. A build that works from the root without install proves the project is self-contained.

5Rules for CI

CI should build the whole reactor from a clean workspace with mvn verify. That compiles, runs unit and integration tests and every check bound to verify, and proves that the modules build together from source. It should not run install, because nothing on the agent needs the artifacts afterwards, and on shared agents a shared local repository makes builds affect each other.

Publishing artifacts for other projects is a separate step: mvn deploy runs only in the pipeline for main or for releases, so only reviewed code reaches the shared repository. If a later CI stage needs the built jars, it should get them from that stage's workspace or from the artifact repository, not from a local install.

6Follow-up questions

Is install ever the right command?

Yes, when another, separate project on the same machine needs to use our snapshot, for example testing a library change in an application from a different repository before publishing it. That is a deliberate, occasional action, not a step before every build.

Why does mvn compile at the root sometimes fail when a module needs a test-jar from a sibling?

Because in early phases the reactor can offer a sibling's target/classes, but a test-jar only exists after the package phase. Running up to package or verify, or restructuring shared test code into a normal module, avoids it. Behaviour around this has changed between Maven versions, so check the version in use.

How can we stop people building modules in isolation by mistake?

Document the -pl and -am commands in the README, provide a small script or Maven wrapper alias for common module builds, and make sure CI always builds from the root so a project that only works with installed artifacts fails quickly.

7Conclusion

In this answer, we saw that the reactor resolves sibling modules from the current build, so building from the root with mvn verify or mvn package needs no install. Stale code appears only when a module is built alone, because its siblings then come from ~/.m2, which contains whatever was installed last. Building from the root with -pl module -am, and -amd for downstream checks, fixes the workflow. Installing from many branches pollutes the local repository and hides version mistakes, so CI runs mvn verify and only the main or release pipeline deploys.

What to say in the interviewAbout 80 seconds aloud

Open with

The developer is solving a real symptom with the wrong habit. When Maven builds from the root, the reactor sorts the modules and resolves each sibling from the current build output, so service sees api's latest code without any install, and mvn verify or package at the root is enough.

Then, if they want more

The stale code appears when someone runs Maven inside a single module folder. Then the reactor contains only that module, so its siblings must come from the local repository in .m2, which holds whatever was installed last, possibly from another branch. That is why installing first seemed to fix it.

The proper fix is to build from the root with -pl to select the module and -am to also make the modules it depends on, so everything resolves inside one reactor, and -amd when I want to check the modules that depend on my change.

I would also explain why installing everywhere is harmful: snapshots are not per branch, so the local repository mixes branches, and stale jars hide version mistakes that only show up on a clean machine. In CI I run mvn verify on a clean workspace, never install, and only the main or release pipeline runs deploy to publish artifacts.

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 "A developer says 'mvn install' is required before every build of your multi-module...": https://scrivio-interview-library.netlify.app/java/maven/a7ecd81a6f/