Scrivio Interview library
ScenarioFoundations6 min read · updated 12 November 2026

Your Maven build takes 8 minutes locally. Name the first things you would try to speed up the edit-compile-test loop.

First I would stop building everything: build only the module I am working on with -pl and -am, and run only the relevant tests with -Dtest. Then I would try parallel module builds with -T, look for slow plugins, avoid clean so incremental compilation can work, and use the Maven Daemon (mvnd) to keep a warm JVM between builds. Slow integration tests belong in a separate profile or in the integration-test phase, so the everyday loop runs only fast tests.

Why this question is asked

An eight-minute build is not just eight minutes. A developer who waits that long switches to email or chat, loses the thread, and starts batching changes to avoid waiting, which makes every problem harder to find. Interviewers ask this to see whether we know Maven well enough to make the everyday loop fast without changing what CI checks. In this answer, we will first find out where the time goes, then go through the fixes in the order I would try them, from the cheapest to the most structural.

1First, Find Out Where the Time Goes

Before changing anything, we measure. Maven prints a reactor summary at the end of a multi-module build with the time per module, which immediately shows whether one module dominates. Running with -X is too noisy, but a profiling extension such as maven-profiler, or a Develocity build scan where available, shows the time per plugin goal. Typical findings are that most of the time is spent in tests, in one large module, or in a plugin that does not need to run on every build, such as JavaDoc generation, a frontend build or a code formatter checking the whole tree.

Text
[INFO] Reactor Summary for shop 1.0.0-SNAPSHOT:
[INFO] shop-common ........................................ SUCCESS [ 12.4 s]
[INFO] shop-domain ........................................ SUCCESS [ 41.0 s]
[INFO] shop-api ........................................... SUCCESS [ 28.7 s]
[INFO] shop-app ........................................... SUCCESS [05:31 min] <- integration tests here
[INFO] Total time: 07:58 min

Here the answer is obvious: one module, with its integration tests, takes most of the time. The rest of the fixes are about not paying that cost on every edit.

2Build Only What You Are Working On

Maven builds the whole reactor by default, but we rarely need that while editing one module. The -pl option, project list, selects modules, and -am, also make, adds the modules they depend on. Combined with -Dtest, which runs only the named test classes or methods, this often turns minutes into seconds.

Java
# build only shop-domain and what it depends on
mvn -pl shop-domain -am test # 54 s instead of 8 min
# run one test class, or one method, in that module
mvn -pl shop-domain -am test -Dtest=PriceCalculatorTest -Dsurefire.failIfNoSpecifiedTests=false
mvn -pl shop-domain test -Dtest='PriceCalculatorTest#appliesCoupon'
# after changing shop-common, also rebuild the modules that depend on it
mvn -pl shop-common -amd test

Notice -Dsurefire.failIfNoSpecifiedTests=false. With -am, Maven also builds upstream modules that do not contain the named test, and without this property Surefire fails in those modules because the pattern matched nothing. -amd, also make dependents, is the reverse of -am and is useful after changing a shared module.

3Parallel Builds and Slow Plugins

Modules that do not depend on each other can be built at the same time. -T 1C runs one thread per CPU core, so on an eight-core laptop independent modules build in parallel. The gain depends on the shape of the dependency graph: a chain where each module depends on the previous one cannot be parallelised, while a wide graph can halve the time. Most common plugins are thread-safe, and Maven warns about plugins that are not.

Then look at plugins. A plugin that runs on every build but is only needed for releases, such as javadoc, source jars, license checks or a full frontend build, can move into a profile that CI activates. Some plugins have skip properties, such as -Dcheckstyle.skip or -Djacoco.skip, which are fine for local loops as long as CI runs everything.

4Avoid clean, Use a Warm JVM

Many developers type mvn clean install by habit. clean deletes target, so every build recompiles every class and reprocesses every resource. Without clean, the compiler plugin can skip work when nothing has changed in a module, and the jar step may not need to repackage. Incremental compilation in Maven is less fine-grained than Gradle's, and sometimes it recompiles a whole module when one file changes, but skipping unchanged modules alone saves a lot. We still use clean when something strange happens, such as deleted classes lingering in target.

Every mvn command also starts a fresh JVM, loads Maven and all its plugins, and runs them before the JIT compiler has warmed up. The Maven Daemon, mvnd, keeps a Maven JVM running in the background and reuses it, with plugins loaded and code already compiled to machine code. It also builds modules in parallel by default. For a large build, consecutive runs with mvnd are often noticeably faster than with plain mvn; it is a drop-in replacement for most commands.

Text
mvnd -pl shop-domain -am test # first run: about as fast as mvn
mvnd -pl shop-domain -am test # second run: warm daemon, often much faster

5Move Slow Integration Tests Out of the Inner Loop

Finally, separate fast tests from slow ones. Unit tests run with Surefire in the test phase; integration tests, which start a Spring context, Testcontainers or an embedded server, belong in Failsafe, which runs in the integration-test phase and by convention picks up classes ending in IT. Then mvn test runs only the fast tests, and mvn verify runs everything, which is what CI does.

XML
<!-- pom.xml: integration tests run with Failsafe in mvn verify, not in mvn test -->
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals><goal>integration-test</goal><goal>verify</goal></goals>
</execution>
</executions>
</plugin>
// CheckoutFlowIT.java -> Failsafe, mvn verify
// PriceCalculatorTest.java -> Surefire, mvn test
Step throughA faster edit-compile-test loop
  1. Read the reactor summarywhich module and plugin take the time
  2. Build one module-pl module -am, -Dtest=...
  3. Parallel and lean plugins-T 1C, release-only plugins in a profile
  4. Drop clean, use mvndskip unchanged work, warm JVM
  5. Split slow tests*IT in Failsafe, run with mvn verify

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

Each step removes work from the inner loop without removing it from CI.

So the everyday loop is mvn test on one module, in seconds, and the full mvn verify runs before pushing and on CI. Nothing is lost; the slow checks just run at the right moment.

6Follow-up questions

Is mvn install needed for local development?

Often not. Building with -pl and -am inside the reactor resolves sibling modules directly, so we do not need to install them into the local repository first. install is needed when another, separate project depends on our module.

Does -o, offline mode, help?

It can save the time Maven spends checking remote repositories for SNAPSHOT updates and new metadata, which is noticeable on slow networks. It fails if a dependency is missing locally, so it suits repeated local builds after one online build.

When is a build cache worth it?

For large multi-module builds where CI and developers build the same modules repeatedly, the Maven Build Cache Extension or a remote cache can skip modules whose inputs have not changed. It needs careful configuration of inputs, so it comes after the simpler fixes above.

7Conclusion

In this answer, we made an eight-minute Maven build fast for everyday work. We measured with the reactor summary, built only the module in hand with -pl and -am and ran selected tests with -Dtest, used -T for parallel modules and moved slow plugins into profiles, avoided clean so unchanged work is skipped, used mvnd for a warm JVM, and moved integration tests to Failsafe so mvn test stays fast while CI still runs everything.

What to say in the interviewAbout 70 seconds aloud

Open with

First I would look at the reactor summary to see which module and which plugin take the time, because usually one module with integration tests dominates. Then the biggest win is to stop building everything: mvn with -pl for the module I am working on and -am for its dependencies, and -Dtest to run just the test class or method I am changing, with surefire failIfNoSpecifiedTests set to false so upstream modules do not fail.

Then, if they want more

That alone often takes eight minutes down to under a minute. Next I would try -T 1C for parallel module builds, and move plugins that are only needed for releases, like javadoc or license checks, into a profile that CI enables.

I would drop clean from the everyday command so unchanged modules are not recompiled, and use the Maven Daemon, mvnd, which keeps a warm JVM with plugins loaded, so repeated builds are faster.

Finally I would make sure slow integration tests are named IT and run by Failsafe in the integration-test phase, so mvn test runs only fast unit tests and mvn verify, which CI runs, still runs everything.

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.
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 "Your Maven build takes 8 minutes locally. Name the first things you would try to speed...": https://scrivio-interview-library.netlify.app/java/version-control-and-ci/f6384d2de9/