Chapter 5 Maven Core Concepts - Warehouse

What is a warehouse?

A warehouse is first and foremost a place, and secondly, a warehouse is used to keep things. In the same way, the maven warehouse is also a place, and it is also used to keep things. So, where is the maven warehouse, and what is it kept?

The maven warehouse stores many components, which are what we call third-party jars, such as junit, spring jars, etc., and the location of the warehouse is different according to its classification.

Classification of maven warehouse



 local warehouse

As the name suggests, it is on our local disk, that is, a directory on the local disk. We have configured the path of the local repository when we installed maven before, in <localRepository>D:\mvnRepository< in $M2_HOME/conf/settings.xml /localRepository> specified. It corresponds to a directory on the disk. Find this directory and you can see that maven manages these dependencies according to certain rules. The basic rules are as follows: groupId / artifactId / version / artifactId-version.packaging, and then create the corresponding directory according to the path, This becomes the layout of the maven repository;

 

remote warehouse

As the name suggests, it is located at the far end. According to the different locations, it is divided into central warehouse, private server, and mirror warehouse.

 

Central warehouse:

The central warehouse is built in maven, the largest warehouse can be understood as a big boss; by default, after we build a new maven project, when we run it for the first time, the console can see that maven is downloading things, and the whole process may be quite Slow, because maven needs to build the central warehouse now, and the central warehouse is located abroad, due to network and other reasons, the entire download process will be quite slow;

Private server: Private server is an application of proxy technology. Since it is relatively slow to download components from the central warehouse, we can access the private server and let the private server download from the central warehouse. After the private server is downloaded to the component, it will be cached, so that subsequent requests can be directly cached The components are returned, no need to download, the private server is generally built in the company or organization's internal LAN, so the speed and stability will be improved;

Mirror repository:

The role of the mirror repository is similar to the concept of an interceptor. For example, we originally requested a repository to download components. We can transfer these requests to other warehouses by mirroring, so that maven will download components from other warehouses.

 

The central repository is built into maven, we don't need to configure it

Private servers or other remote repositories are configured as follows:

In the project's pom file, add the following configuration:

<repositories>
    <repository>
        <id>nexus</id>
        <name>Team Nexus Repository</name>
        <url>http://10.80.6.34:8081/nexus/content/groups/public</url>
    </repository>
</repositories>

 Configure a warehouse through the repository element, a warehouse includes id, name, url, different warehouses, ids cannot conflict, url indicates the network address of the warehouse

Mirror repository configuration:

The configuration of the mirror warehouse is in maven's settings.xml


 Configure the address of the mirror warehouse through the mirror element. The mirrorOf element configures which warehouse you want to mirror. As above, the configured mirror warehouse is the warehouse of Alibaba Cloud, and central represents the central warehouse, which means that the original request to the central warehouse is now Transfer it to the Alibaba Cloud warehouse.

 

Mechanism for repository resolution dependencies


 maven first looks for dependencies in the local repository. If there is no local repository, it will look for it from the remote repository. If we configure other repositories or private servers, it will look for these repositories first. If it is not found, it will look for it from the central repository. During this period, if the configuration If a mirror is found, look for dependencies from the corresponding mirror repository.

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326776729&siteId=291194637