Understanding of Maven Repositories

By | October 27, 2020

This post talks about Understanding of Maven Repositories 

What is Maven Repositories?

Maven downloads the required artifacts or dependencies (jar files) and other plugins which are configured as part of any project, there must be a commonplace where all such artifacts are placed. This common shared area is called a Repository.

Maven repositories are classified into 3 main categories:

1.Local Repository
2.Remote Repository
3.Central Repository

Local Repository:

This repository usually resides in our local machine. Which is cached from the remote/central repository downloads and ready for usage/reuse.

The directory to store all the dependencies in the local machine can be configured in the settings.xml file of the maven directory under the tag <localRepository>

Remote Repository:

This repository as the name suggests resides in the remote server and can be accessed by using different file transfer protocols like file:// or http://.

The remote repository can be used for both downloading and uploading the dependencies and artifacts.

Central Repository:

This is the repository provided by the maven community. This repository contains a large set of commonly used/required libraries for any java project.

Always keep in mind that we need an internet connection to use the central repository but no configuration is required to access this central repository(Optionally you can configure it).

How does Maven search for Dependencies?

when maven starts building the project by executing the build commands, maven starts searching the dependencies as explained below:

  • First of all, maven scans through the local repositories for all the project dependencies. If found, then it continues with further execution. If the project dependencies configured are not found in the local repository, then it scans through the central repository.
  • If the configured dependencies are available in the central repository then those dependencies will be downloaded to the local repository for future reference and usage. If not found, then the maven starts scanning into the remote repositories.
  • If the remote repository has not been configured then maven will throw an exception with an error message not able to find the dependencies and stops further processing. If found, then those dependencies are downloaded to the local repository for future reference and usage.

That’s all about Understanding of Maven Repositories?
If you have any feedback or suggestion please feel free to drop in below comment box.

Leave a Reply

Your email address will not be published. Required fields are marked *