Maven Local Repository

Last Updated : 23 Mar, 2026

Maven is a build automation tool used primarily for Java projects. The Maven Local Repository is a directory on the developer’s system where all downloaded dependencies are stored. When building a project, Maven first checks this local repository before downloading from remote repositories.

  • Stores all project dependencies locally for faster access
  • Reduces repeated downloads from remote repositories
  • Acts as the first place Maven checks during dependency resolution

Default Location

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. By default, this repository is located at:

Windows: C:\Users\{your-username}\.m2\repository
Unix-based systems: ~/.m2/repository

On Windows:

Repository Location

How the Maven Local Repository Works

When a Maven build runs, it first checks the local repository for required dependencies. If they are not found, Maven downloads them from remote repositories and stores them locally. These dependencies are then reused from the local repository in future builds.

Working Of Maven Local Repository

Explanation:

Below we provide step by step how maven local repository works for better understanding.

  • Maven Build: The Maven Build process is started when you run maven build command like mvn clean and mvn install.
  • Check Local Repository: After this Maven first checks local repository for required dependencies in this location ~/.m2/repository.
  • Dependencies Found Locally: If required dependencies are available in the local repository then maven will use them.
  • Dependency Not Found Locally: If required dependencies are not available in the local repository then Maven checks remote repositories.
  • Download from Remote: If the dependency is available in a remote repository, Maven downloads it and stores it in the local repository.
  • Use Downloaded Dependency: Once downloaded, Maven uses the dependency from the local repository for the build process.

This workflow ensures that Maven projects can be built efficiently by reusing previously downloaded dependencies and only downloading missing ones when necessary.

Example Maven Project

Step 1: Create a Maven Project

We can create the project using Maven command:

mvn archetype:generate -DgroupId=com.app -DartifactId=mavencommends -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

Step 2: Update pom.xml

  • Uses Spring Boot parent (spring-boot-starter-parent)
  • spring-boot-starter-web -> for web app
  • spring-boot-devtools -> for development
  • spring-boot-starter-test -> for testing
XML
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.6</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.app</groupId>
    <artifactId>mavencommends</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>mavencommends</name>
    <description>Spring Reactive</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

Step 3: Create Main Class

Create the main class and add

Main Application Class:

Java
package com.app;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;

@SpringBootApplication
public class MavenApp {

    public static void main(String[] args) {
        SpringApplication.run(MavenApp.class, args);
      System.out.println("Welcome to GeeksForGeeks")
    }

}

Step 4: Build the Project

Run the following command:

mvn clean install

Step 5: Run the Application

1: Using Maven

mvn spring-boot:run

2: Using JAR

java -jar target/mavencommends-0.0.1-SNAPSHOT.jar

Step 7: Verify Output

After running, you should see:

Welcome to GeeksForGeeks


Applications of Maven Local Repository

The Maven provide lot application for make development easy.

  • Dependency Management: Simplifies dependency management by automatically handling downloads and updates.
  • Offline Builds: Allows for offline builds using previously downloaded dependencies.
  • Custom Repositories : Supports custom local repositories for internal libraries and artifacts.
  • Build Performance: Speeds up builds by reusing previously downloaded dependencies and Reduces the need to download dependencies multiple times.
  • Version Control: Facilitates easy rollback to previous versions if needed.
Comment
Article Tags:

Explore