Ten years of JAVA moving bricks - the relationship between Maven warehouse priority and maven mirror

**

Maven repository priority

**
Local>Project>Global Storage>Central

Maven sets the location of the local warehouse.
Find the localRepository in the settings.xml file under the conf folder
and add it

  <localRepository>你需要存放的地址</localRepository>

Maven project warehouse settings
are added in the POM file

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://com.xxx.xxx/repository/maven-public/</url>
    </repository>
</repositories>

Maven global repository settings
are added in settings

<repositories>
        <repository>
            <id>com.e-iceblue</id>
            <name>e-iceblue</name>
            <url>https://com.xxx.xxx/repository/maven-public/</url>
        </repository>
    </repositories>

Maven central repository settings

Add in settings

<repositories>
  <repository>
    <id>central</id>
    <url>https://repo.maven.apache.org/maven2</url>
  </repository>
</repositories>

Maven mirror

Configure in, such as configuring Ali Mirror

  <mirrors>
        <mirror>
	      <id>nexus-aliyun</id>
	      <mirrorOf>central</mirrorOf>
	      <name>Nexus aliyun</name>
	      <url>http://maven.aliyun.com/nexus/content/groups/public</url>
	  </mirror>
   </mirrors>

How to understand the relationship between warehouse and mirror image?

When Maven comes to fetch the jar package, it will pull it from the warehouse first. If the warehouse does not exist or the warehouse has a corresponding mirror configuration, it will pull the jar package from the corresponding mirror to achieve the purpose of speeding up.
The so-called corresponding configuration is mainly determined by the value in central. For example, central corresponds to the center in the warehouse, and the default warehouse of maven is central. So we configure the Ali image and use central. In this way, when a certain jar package needs to be pulled from the center warehouse, it will be accelerated through the proxy through the Ali image.

In layman's terms, if Maven is configured with a mirror of the Maven central warehouse, then when it is necessary to obtain dependencies from the central warehouse, Maven will search for the mirror source according to the configured mirror address. If the required dependencies exist on the mirror source, Maven will download the dependent files directly from the mirror source. If the required dependencies do not exist on the mirror source, Maven will fall back to the central warehouse itself to find and download the dependent files. This can speed up the download speed of dependencies and reduce the load pressure on the central warehouse.

Guess you like

Origin blog.csdn.net/weixin_43485737/article/details/132355008