Explain how you would optimize Maven build speeds for large projects.

Optimizing Maven build speed on a large project means reducing redundant compilation, downloading, and module rebuilding by using parallelism, caching, and smarter dependency management. The goal is to only do the work that's actually necessary for the current change.

Key Points: • Use the -T flag for parallel multi-module builds, e.g. mvn install -T 1C to use one thread per CPU core. • Use mvn -o (offline mode) locally once dependencies are cached, avoiding repeated network resolution. • Run a local repository manager like Nexus or Artifactory so dependency downloads are served from a fast local cache instead of the internet. • Use the maven-dependency-plugin's analyze goal to find and remove unused or duplicate dependencies, shrinking the resolution graph. • Split unrelated modules so unaffected ones can be skipped with -pl and -am (build only the changed module and its dependents). • Keep Maven and plugin versions current, since newer versions often include resolver and caching performance improvements.

Example: On a 40-module enterprise project, switching from a sequential build to mvn install -T 1C combined with an Artifactory proxy for dependency caching reduced full build time from around 25 minutes to under 10.

Interview Tip: A concise interview answer is:

"For large Maven builds I'd enable parallel builds with -T 1C, put a repository manager like Nexus in front of dependency downloads to speed up resolution, and prune unused dependencies. I'd also use -pl/-am to build only affected modules during local development instead of rebuilding the whole reactor every time."