The Maven Repository is a storage location where Maven stores and retrieves project dependencies, including JAR files, libraries, and plugins. It helps manage and share code efficiently during the build process.
There are three primary types of Maven repositories:
- Local
- Central
- Remote

1. Local Repository
A local repository is a directory on the developer's machine where Maven stores all the artifacts resolved from remote repositories or created by the developer. And by default, this repository is located at:
C:\Users\{your-username}\.m2\repository
When a dependency is needed, Maven first checks this local repository. If dependency is found, it is used; Otherwise, Maven fetches it from the remote repositories and caches it locally.
Example Steps
Step 1: Create a new Maven project using your preferred IDE (e.g., IntelliJ IDEA, Eclipse) or by running the following command:
mvn archetype:generate -DgroupId=com.geeks -DartifactId=Maven-repo-demo -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Step 2: add a simple dependency to your pom.xml file to download JUnit for testing.
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Step 3: Save with ctrl+s or run the following command to compile the project and download the dependency:
mvn clean install
Step 4: Verify the Local Repository:
After running the above command, Maven will download the JUnit dependency from Maven Central Repository (since it doesn't exist in your local repository yet) and store it in your local repository.
Check at - ~/.m2/repository
2. Central Repository
The central repository is a repository provided by the Maven community and maintained by the Apache Software Foundation. It contains a large number of commonly used libraries and is the default repository used by Maven When It needs to resolve dependencies.
https://repo.maven.apache.org/maven2/
Example:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
When a dependency is not found in the local repository, Maven queries the central repository to download it.
3. Remote Repository
Remote repositories are repositories other then the central repository that can be set up by third parties or any organizations to host their own artifact. They are specified in the project's pom.xml file in the Maven Settings.
Example:
<repositories>
<repository>
<id>my-internal-repo</id>
<url>http://my-company.com/repo</url>
</repository>
</repositories>
If an artifact is not available in the local repository, Then Maven will check these remote repositories for the required dependencies.
Maven repositories are an essential part of managing dependencies in Maven-based projects. With Maven, you can efficiently manage dependencies, resolve versioning conflicts, and integrate external libraries, greatly simplifying the build process.