【 构建maven工程时,配置了阿里云的前提下,依旧使用中央仓库下载依赖导致失败的问题!】

构建maven工程时,配置了阿里云的前提下,依旧使用中央仓库下载依赖导致失败的问题!!!

错误提示信息:

Cannot download ZIP distribution from https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip. Please check distributionUrl The Maven wrapper was disabled. The Maven bundled version will be used instead.

问题原因:

由于在构建项目时,我们在setting中已经配置了阿里云镜像,但是下载依赖还是会遵从super pom(所有自定义pom.xml都是继承自super pom),因此,当maven项目需要下载一些metadata、pom、jar的时候,会优先去中央仓库下载,导致内网用户各种报错!

问题解决方法

1、在maven的setting.xml文件的中添加仓库地址,如下:

xml 复制代码
<mirror>
            <id>alimaven</id>
            <mirrorOf>central</mirrorOf>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
        </mirror>
        <mirror>
            <id>alimaven</id>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
        <mirror>
            <id>central</id>
            <name>Maven Repository Switchboard</name>
            <url>http://repo1.maven.org/maven2/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
        <mirror>
            <id>repo2</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://repo2.maven.org/maven2/</url>
        </mirror>
        <mirror>
            <id>ibiblio</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
        </mirror>
        <mirror>
            <id>jboss-public-repository-group</id>
            <mirrorOf>central</mirrorOf>
            <name>JBoss Public Repository Group</name>
            <url>http://repository.jboss.org/nexus/content/groups/public</url>
        </mirror>
        <mirror>
            <id>google-maven-central</id>
            <name>Google Maven Central</name>
            <url>https://maven-central.storage.googleapis.com
            </url>
            <mirrorOf>central</mirrorOf>
        </mirror>
        <!-- 中央仓库在中国的镜像 -->
        <mirror>
            <id>maven.net.cn</id>
            <name>oneof the central mirrors in china</name>
            <url>http://maven.net.cn/content/groups/public/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>

2、在idea中设置好maven的setting.xml和仓库路径(可以看idea创建maven项目这篇文章中设置项目创建时默认maven配置)

3、在pom.xml中添加阿里云的镜像(注意这个镜像一定要和setting.xml中的镜像一样)

xml 复制代码
<repositories>
		<repository>
			<id>nexus-aliyun</id>
			<name>nexus-aliyun</name>
			<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
	</repositories>

4、重新加载maven就可以成功构建了!

相关推荐
非 白2 分钟前
【Java分布式】Nacos注册中心
java·开发语言·nacos·注册中心
吃海鲜的骆驼7 分钟前
服务异步通讯与RabbitMQ
java·分布式·后端·rabbitmq
羱滒10 分钟前
sql调优之数据库开发规范
java·数据库·数据库开发
Forget the Dream39 分钟前
设计模式之责任链模式
java·c++·设计模式·责任链模式
jonyleek42 分钟前
「JVS更新日志」低代码、企业会议、智能BI、智能排产2.26更新说明
java·大数据·低代码·数据分析·软件需求
令狐少侠20111 小时前
Idea 和 Pycharm 快捷键
pycharm·intellij-idea·idea
计算机小白一个1 小时前
蓝桥杯 Java B 组之最短路径算法(Dijkstra、Floyd-Warshall)
java·数据结构·算法·蓝桥杯
曼岛_1 小时前
[密码学实战]Java实现SM4加解密(ecb,cbc)及工具验证
java·密码学
吃汤圆的抹香鲸1 小时前
GoLand 安装包 绿色版 Win,Mac,Linux 包含IntelliJ全家桶 专为Go语言设计的集成开发环境(IDE)
linux·windows·macos·go·intellij-idea·go1.19
Forget the Dream2 小时前
设计模式之代理模式
java·c++·设计模式·代理模式