May 26, 2021 Maven
In Maven's terminology, a repository is a place, such as a directory, that stores all project jar files, library jar files, plug-ins, or any other project-specified files.
There are three types of Maven warehouses:
Maven's local repository is a folder on the machine. It is created the first time you run any maven command.
Maven's local repository holds all the dependencies of your project (library jar, plugin jar, etc.). W hen you run a Maven build once, Maven automatically downloads all dependent jar files to the local repository. It avoids referencing dependent files stored on remote machines every time you build.
Maven local repositories are created by default in the %USER_HOME% directory. To modify the default location, define another path in Maven's settings file in the %M2_HOME%?conf directory.xml the settings file.
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>C:/MyLocalRepository</localRepository>
</settings>
When you run the Maven command, Maven downloads the dependent files into the path you specify.
Maven Central Warehouse is a warehouse provided by the Maven community and contains a number of commonly used libraries.
Key concepts of a central warehouse:
To browse the contents of the central repository, the maven community provides a URL: http://search.maven.org/#browse. Using this repository, developers can search for all available code libraries.
If Maven also can't find the dependent library files in the central repository, it stops the build process and outputs an error message to the console. To avoid this, Maven provides the concept of a remote repository, which is a developer's own custom repository that contains the required code base or jar files used in other projects.
For example, using the following POM .xml, Maven will download from the remote repository the dependent (not available in the central repository) files that are declared in the pom.xml.
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.companyname.projectgroup</groupId>
<artifactId>project</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>com.companyname.common-lib</groupId>
<artifactId>common-lib</artifactId>
<version>1.0.0</version>
</dependency>
<dependencies>
<repositories>
<repository>
<id>companyname.lib1</id>
<url>http://download.companyname.org/maven2/lib1</url>
</repository>
<repository>
<id>companyname.lib2</id>
<url>http://download.companyname.org/maven2/lib2</url>
</repository>
</repositories>
</project>
When we execute the Maven build command, Maven starts looking for dependent libraries in the following order: