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:
<settings> ... <mirrors> <mirror> <id>internal-repository</id> <name>Maven Repository Manager running on </name> <url>/proxy</url> <mirrorOf>*</mirrorOf> </mirror> </mirrors> ... </settings>
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!