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

问题描述:

在使用spring进行构建项目时,出现下载依赖迟迟不成功,显示maven wrapper 下载失败的问题。

Maven wrapper Cannot download ZIP distribution from https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip. Please check distributionUrl The Maven wrapper was disabled. The Mavenbundled version will be used instead. Re-enable Maven wrapper in settings.

回顾maven配置:

在配置maven项目前,一般都会进行两个步骤

1.本地仓库的配置

  • 将maven进行下载并解压——配置maven的环境变量——cmd中验证maven是否配置成功
  • 新建repository本地仓库,以及maven的配置文件setting.xml

  •  setting.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">

    <pluginGroups />
    <proxies />
    <servers />

    <localRepository>D:/server/maven/repository</localRepository>

    <mirrors>
        <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>
    </mirrors>

</settings>
  • 其中,本地仓库路径需要进行修改(根据自己的文件路径修改即可)。

2. IDEA中的配置

在IDEA中主要是进行路径修改,file-->settings-->Build,Execution,Deployment-->Maven

进行如下修改:

 以上,maven的下载和配置结束。

问题原因:

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

解决方案:

在pom.xml中添加阿里云的镜像(注意这个镜像一定要和setting.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>

如下的代码也可以加上,我这加上不加上影响不大,也是从其他博主文章中看见的。

<pluginRepositories>
		<pluginRepository>
			<id>central</id>
			<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
		</pluginRepository>
	</pluginRepositories>

OK,到这就配置结束了,成功解决下载失败的问题。

但是好像之后再配置新的项目,这段代码还是得再添加一下。

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值