maven设置多个镜像源,按顺序下载依赖
2022/8/24 23:27:03
本文主要是介绍maven设置多个镜像源,按顺序下载依赖,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
目标
分别配置两个nexus镜像源,目的: 编译时,先从nexus1尝试下载依赖,如果失败,到nexus2下载依赖,再失败,去公网中央仓库下载镜像
配置
settings.xml
<?xml version="1.0" encoding="UTF-8"?> <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"> <mirrors> <mirror> <id>nexus1</id> <mirrorOf>nexus1</mirrorOf> <url>http://nexus1.com/nexus/repository/maven-delivery/</url> </mirror> <mirror> <id>nexus2</id> <mirrorOf>nexus2</mirrorOf> <url>http://nexus2.com/repository/maven-public/</url> </mirror> </mirrors> <!-- 配置连接密钥,如果需要认证 --> <servers> <server> <id>nexus1</id> <username>demo</username> <password>demo001</password> </server> </servers> <!-- The resolution of multiple Repositories only works with profiles!--> <profiles> <profile> <id>nexus</id> <repositories> <repository> <id>nexus1</id> <url>http://nexus1.com/nexus/repository/maven-delivery/</url> <snapshots> <enabled>false</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </repository> <repository> <id>nexus2</id> <url>http://nexus2.com/repository/maven-public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus1</id> <url>http://nexus1.com/nexus/repository/maven-delivery/</url> <snapshots> <enabled>false</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </pluginRepository> <pluginRepository> <id>nexus2</id> <url>http://nexus2.com/repository/maven-public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles> </settings>
测试
使用mvn插件下载一个不存在的依赖,查看效果
mvn dependency:get -DgroupId=com.github.ggdefe -DartifactId=ggdefe -Dversion=1.0.0
输出
这篇关于maven设置多个镜像源,按顺序下载依赖的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-27OpenFeign服务间调用学习入门
- 2024-12-27OpenFeign服务间调用学习入门
- 2024-12-27OpenFeign学习入门:轻松掌握微服务通信
- 2024-12-27OpenFeign学习入门:轻松掌握微服务间的HTTP请求
- 2024-12-27JDK17新特性学习入门:简洁教程带你轻松上手
- 2024-12-27JMeter传递token学习入门教程
- 2024-12-27JMeter压测学习入门指南
- 2024-12-27JWT单点登录学习入门指南
- 2024-12-27JWT单点登录原理学习入门
- 2024-12-27JWT单点登录原理学习入门