What strategies would you use to reduce the size of a Maven project?

Reducing a Maven project's size means minimizing both the source/dependency footprint and the size of the final packaged artifact, which improves build speed, deployment time, and container image size. This is done through dependency pruning and packaging optimizations.

Key Points: • Remove unused or duplicate dependencies identified via mvn dependency:analyze. • Prefer lighter-weight libraries over heavyweight ones when the extra functionality isn't needed (e.g. a focused HTTP client instead of a full framework). • Use <exclusions> to strip unwanted transitive dependencies that bloat the final artifact. • Configure the maven-shade-plugin or maven-assembly-plugin to remove duplicate classes and unused resources when building an uber-jar. • Scope dependencies correctly (test, provided) so they don't get bundled into the final deployable artifact unnecessarily. • For containerized deployments, consider layered JARs (Spring Boot's layertools) so unchanged dependency layers aren't re-pushed.

Example: A service that only needed to send a handful of HTTP requests was pulling in a full-featured SDK; swapping it for a lightweight client and adding exclusions for its unused transitive dependencies cut the packaged JAR from 85MB to 22MB.

Interview Tip: A concise interview answer is:

"I'd start by running dependency:analyze to find unused dependencies, then use exclusions to strip unnecessary transitive dependencies. For the packaged artifact itself, I'd configure the Shade or Assembly plugin to drop duplicate classes and unused resources, and make sure test-scoped dependencies never leak into the deployable jar."