Maven Repositories - Maven

What is a Maven Repository?

As per the Maven terminology, a repository is a directory which stores all the project jars, library jar, plugins or any other project specific artifacts to be used by Maven.
Usually Maven repository includes three types which may be includes following.
  • local
  • central
  • remote

Local Repository

  • Maven local repository is known as a folder location on your machine. Local repository is created when you run any maven command for the first time.
  • Maven local repository includes your project's all dependencies like library jars, plugin jars etc. While you are running a Maven build, then Maven automatically downloads all the dependency jars into the local repository. Then it may be useful to avoid references to dependencies stored on remote machine every time a project is build.
  • Maven local repository is created by default in %USER_HOME% directory. You can mention another path to override the directory in Maven settings.xml file available at %M2_HOME%\conf directory.
While running the Maven command it will download dependencies to your custom path.

Central Repository

Maven central repository is created by Maven community which includes large number of commonly used libraries.
If you does not find any dependency in local repository, then it starts searching in central repository using following URL − https://repo1.maven.org/maven2/
Key concepts of Central repository are as follows −
  • This repository is managed by Maven community.
  • It is not required to be configured.
  • It requires internet access to be searched.
You can search the content of central maven repository, maven community has provided a URL − https://search.maven.org/#browse. It is useful to search all the available libraries in central repository by the developers.

Remote Repository

Incase if you doesn’t find any mentioned dependency in central repository as well the it stops the build process and output error message to console. To overcome this scenario,Maven provides concept of Remote Repository, which is developer's own custom repository containing required libraries or other project jars.
You can use below mentioned POM.xml, Maven will download dependency (not available in central repository) from Remote Repositories mentioned in the same pom.xml.

Maven Dependency Search Sequence

Maven build commands executed in in the following sequence −
  • Step 1 – Here you need to search dependency in local repository, if not found, move to step 2 else perform the further processing.
  • Step 2 – Then search dependency in central repository, if not found and remote repository/repositories is/are mentioned then move to step 4. Otherwise it is downloaded to local repository for future reference.
  • Step 3 – Incase if any remote repository has not been mentioned, Maven simply stops the processing and throws error (Unable to find dependency).
  • 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 error (Unable to find dependency).

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Maven Topics