Maven repositories are directories of packaged JAR files with extra meta-data. The meta-data is represented by POM files. A repository contains all the project jars, library jar, plugins and any other project specific artifacts.
Types of maven repository:
- Local Repository
- Central Repository
- Remote Repository
Maven repository search order:
Local repository then Central repository then Remote repository.
Note: Maven stops processing and throws an error if dependency is not found in these repositories.
Maven Local Repository:
Maven local repository is a directory on the developer’s machine. It gets created when we run any maven command for the first time. It contain all the dependencies (downloaded by maven) like library jars, plugin jars etc.
Default location of maven local repository is user-home/.m2 directory. We can change the default location of maven local repository by changing the settings.xml file. It is located in MAVEN_HOME/conf/settings.xml.
<settings> <localRepository> //Set desired location </localRepository> </settings>
Maven Central Repository:
Maven central repository is created by the apache maven community itself. It contains a lot of commonly used libraries. By default Maven looks in this central repository for any dependencies needed but not found in your local repository.
Maven central repository path: http://repo1.maven.org/maven2/.
Maven Remote Repository:
Maven remote repository is a repository on a web server. A remote repository can be located anywhere on the internet or inside a local network. We can configure a remote repository in the POM file. We have to put the following XML elements right after the
<repositories> <repository> <id>w3spoint.code</id> <url>https://maven.w3spoint.com/maven2/lib</url> </repository> </repositories>