Learn about How to Use Maven Repositories

0
2249
Maven Repositories

Maven Repositories

In this article, we are going to discuss the use of different types of Maven repositories which are used to download library JARs, etc. during building a Maven project. A Maven repository can be defined as a directory where all the projects APIs such as JARs, library JARs, plugins, etc. are placed that can be readily used by Maven when required. There are three types of Maven repositories as specified below.

• Local Maven Repository
• Central Maven Repository
• Remote Maven Repository

Local Maven Repository
A local Maven repository is nothing but a folder which is located on your local machine. Maven plugin creates a folder when you execute any maven command for the very first time. The purpose of local repository is to keep all your project related dependencies such as library JARs, plugin JARs, etc. in one place. These dependencies are automatically downloaded into your local repository when you kick in a Maven build. Such a practice is very beneficial as it helps to mitigate the references to dependencies again and again which are available on remote machine during building a Maven project.

By default, a local Maven repository is created at %USER_HOME% directory by Maven plugin. If you want to override this default location, then you need to provide a different path in Maven’s setting.xml file which is present at %M2_HOME%\conf directory. The following will be the content of setting.xml file which has the customized path defined for local Maven repository.

Upon execution of the Maven command, the required project dependencies will be downloaded at your given customized path on your local machine.

Central Maven Repository
Central Maven repository is referred to the repository which is provided by Maven community. It is a giant repository that contains a large number of library JARs which are used very commonly. The following are the key concepts of central Maven repository.

• It is a repository which is wholly managed by the Maven community.
• No configuration is required for this repository.
• Central repository can be searched through internet access. Its content can browsed through a URL − https://search.maven.org/#browse provided by the Maven community. All the library JARs which are available at central repository can be searched and used by developer through this URL.

Remote Maven Repository
Remote Maven repository is very useful and comes into the picture when the required library JARs are not even spotted in the central Maven repository that may result into the failure of build process after throwing the error message on the console. In order to mitigate such situations, the concept of remote Maven repository comes into picture, which is nothing but a customized repository that contains required project’s library JARs. In the following example, the POM.xml has a number of remote repositories which will download the required dependencies (i.e. library JARs) when they are not present on the local repository as well as central repository.

The above POM.xml will download all the dependencies specified in it through the repository URLs present under repositories/repository elements.

Source code for the different maven repositories

Conclusion: –
In this article, we discussed about the different Maven repositories along with a suitable example for each of the type.

LEAVE A REPLY

Please enter your comment!
Please enter your name here