What is a Maven Repository? Type of Maven Repositories - Maven Tutorial



In Maven terminology, a repository is a directory where all the project jars, library jar, plugins or any other project specific artifacts are stored and can be used by Maven easily. 

Maven has three types of repository:

1. Local repository2. Central repository3. Remote repository

Local Repository

A local repository is a directory on the developer’s computer. This repository will contain all the dependencies Maven downloads. The same Maven repository is typically used for several different projects. Thus Maven only needs to download the dependencies once, even if multiple projects depends on them


Central Repository

The central Maven repository is a repository provided by the Maven community. By default, Maven looks in this central repository for any dependencies needed but not found in your local repository. Maven then downloads these dependencies into your local repository. You need no special configuration to access the central repository.


Remote Repository

A remote repository is a repository on a web server from which Maven can download dependencies, just like the central repository. A remote repository can be located anywhere on the internet, or inside a local network.

A remote repository is often used for hosting projects internal to your organization, which are shared by multiple projects.


Maven Dependency Search Sequence

When we execute Maven build commands, Maven starts looking for dependency libraries in the following sequence:

Step 1 − Search dependency in the local repository, if not found, move to step 2 else perform the further processing.

Step 2 − Search dependency in the central repository, if not found and if remote repository/repositories is/are mentioned then go to step 4 else it is downloaded to local repository for future reference.

Step 3 − If a remote repository has not been mentioned, Maven simply stops the processing and throws an error

([ERROR] Failed to execute goal on project Test: Could not resolve dependencies for project Test:Test:jar:1.0.0).

Step 4 − Search dependency in remote repository or repositories, if found then it is downloaded to local repository for future reference. Otherwise, Maven stops processing and throws an error

([ERROR] Failed to execute goal on project Test: Could not resolve dependencies for project Test:Test:jar:1.0.0).