解决构建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

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

  •  setting.xml内容(其中进行阿里云镜像的配置)



    
    
    

    D:/server/maven/repository

    
        
            alimaven
            central
            aliyun maven
            http://maven.aliyun.com/nexus/content/repositories/central/
        
        
            alimaven
            aliyun maven
            http://maven.aliyun.com/nexus/content/groups/public/
            central
        
        
            central
            Maven Repository Switchboard
            http://repo1.maven.org/maven2/
            central
        
        
            repo2
            central
            Human Readable Name for this Mirror.
            http://repo2.maven.org/maven2/
        
        
            ibiblio
            central
            Human Readable Name for this Mirror.
            http://mirrors.ibiblio.org/pub/mirrors/maven2/
        
        
            jboss-public-repository-group
            central
            JBoss Public Repository Group
            http://repository.jboss.org/nexus/content/groups/public
        
        
            google-maven-central
            Google Maven Central
            https://maven-central.storage.googleapis.com
            
            central
        
        
        
            maven.net.cn
            oneof the central mirrors in china
            http://maven.net.cn/content/groups/public/
            central
        
    


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

2. IDEA中的配置

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

进行如下修改:

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

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

问题原因:

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

解决方案:

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


		
			nexus-aliyun
			nexus-aliyun
			http://maven.aliyun.com/nexus/content/groups/public/
			
				true
			
			
				false
			
		
	

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


		
			central
			http://maven.aliyun.com/nexus/content/groups/public/
		
	

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

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

你可能感兴趣的:(maven,阿里云,java)