Maven Repositories: Local, Central, and Remote
Fast recall
Quick revision
Core answer
Understanding of how Maven resolves dependencies — essential for debugging dependency conflicts and build failures
Not knowing about the local .m2 cache — this is why dependencies download once and resolve from disk afterward, avoiding repeated downloads
Mention Nexus and Artifactory as enterprise repository managers and explain why companies use them: security scanning, faster builds, and hosting private internal libraries
Interview-ready guide
Interview answer
A Maven repository stores artifacts and metadata by coordinates. Maven has a local repository on the developer machine and can use one or more remote repositories. Maven Central is the familiar public remote. A company Nexus or Artifactory server is also a remote repository and may proxy Central or host private artifacts.
For example, mvn install places the current project's artifact in the local repository so another local build can resolve it. mvn deploy publishes to the configured deployment repository when credentials and distribution management are set. Deleting part of .m2 is sometimes a troubleshooting step, but it removes cached and locally installed artifacts and causes needed items to be resolved or rebuilt again; it is not inherently dangerous or guaranteed to involve a particular download size.
Maven Repositories: Local, Central, and Remote
Direct Answer
Maven resolves artifacts through a local repository on the developer machine and configured remote repositories. Maven Central is the default public remote in Maven's standard setup; a company Nexus or Artifactory server is another remote and may proxy Central. Central is not a third repository category—it is one remote repository.
Code Example
<!-- pom.xml - configuring custom remote repository -->
<project>
<repositories>
<!-- Company Nexus proxy for faster builds -->
<repository>
<id>company-nexus</id>
<url>https://nexus.company.com/repository/maven-public</url>
</repository>
</repositories>
<dependencies>
<!-- Maven checks: ~/.m2 -> Nexus -> Central -->
<dependency>
<groupId>com.company</groupId>
<artifactId>internal-utils</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>3.2.0</version>
</dependency>
</dependencies>
</project>
Common Mistakes & Pitfalls
- Deleting the .m2 directory thinking it's temporary: Freshers see ~/.m2 taking gigabytes and delete it, then wonder why Maven re-downloads every dependency on the next build. It's a cache that should persist.
- Not understanding the resolution order: They don't realize Maven checks local first, so an offline build can work when every dependency, plugin, parent, and required metadata item is already local.
- Ignoring repository managers in companies: They hardcode Maven Central URLs instead of using the company Nexus, bypassing security scans and slower builds when Central is slow.
Check your understanding
Answer these without looking back at the article.
- What is Nexus Repository?
- How do you add a custom repository to pom.xml?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.