SoFunction
Updated on 2025-03-10

Implementation of Maven warehouse image configuration method

In using Maven, using repository mirrors can accelerate construction. Here we introduce how to use repository mirrors and leave them as notes.

Configuration instructions

Using warehouse image

Configure a repository image to edit configuration files (${}/.m2/):

If ${}/.m2/ is not available, you can copy it from the conf directory of the maven installation directory.

<settings>
  ...
  <mirrors>
    <mirror>
      <id>other-mirror</id>
      <name>Other Mirror Repository</name>
      <url>/maven2</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>
  ...
</settings>

Parameter description:

parameter illustrate
id Mirror ID
name Mirror name
url Mirror url
mirrorOf The target warehouse replaced by mirror warehouse

Using a single warehouse

If you want all maven requests to access a repository (such as a self-built repository), you can specify that maven uses a single repository, and the configuration is as follows:

&lt;settings&gt;
  ...
  &lt;mirrors&gt;
    &lt;mirror&gt;
      &lt;id&gt;internal-repository&lt;/id&gt;
      &lt;name&gt;Maven Repository Manager running on &lt;/name&gt;
      &lt;url&gt;/proxy&lt;/url&gt;
      &lt;mirrorOf&gt;*&lt;/mirrorOf&gt;
    &lt;/mirror&gt;
  &lt;/mirrors&gt;
  ...
&lt;/settings&gt;

Advanced configuration

mirrorOf also supports more advanced syntax, as shown below:

value effect
* Match all repositories
external:* Match all repositories except localhost repositories and file-based repositories
repo,repo1 Match two repo, repo1 repo
*,!repo1 Match all repositories and process repo1

Common usage

Assume that the repository configuration in the project's pom is as follows:

<repositories>
    <repository>
        <id>central</id>
        <url>/maven2</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <repository>
        <id></id>
        <url>/artifactory/cloudera-repos</url>
        <name>Cloudera Repo</name>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <repository>
        <id></id>
        <url>/content/repositories/releases</url>
        <name>Hortonworks Repo</name>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

Usage 1

Use Alibaba Cloud Maven image to replace the central repository, the others remain unchanged, and the configuration is as follows:

<settings>
  ...
  <mirrors>
    <mirror>
      <id>aliyunmaven</id>
      <name>Aliyun Maven</name>
      <url>/repository/public</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>
  ...
</settings>

Usage 2

In addition to and, all use Alibaba Cloud mirrors, and the configuration is as follows:

<settings>
  ...
  <mirrors>
    <mirror>
      <id>aliyunmaven</id>
      <name>Aliyun Maven</name>
      <url>/repository/public</url>
      <mirrorOf>*,!,!</mirrorOf>
    </mirror>
  </mirrors>
  ...
</settings>

refer to:/guides/mini/

This is the end of this article about the implementation of the Maven warehouse image configuration method. For more related content on Maven warehouse image configuration, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!