maven替换中央仓库- 阿里云

在国内访问Maven仓库,连接速度太慢。下面是将中央仓库替换成阿里云的中央仓库的方法。

第一种,统一修改仓库地址

可以直接修改Mavenconf文件夹中的setting.xml文件,或者在.m2文件夹下建立一个setting·xml文件。

setting.xml里面有个mirrors节点,用来配置镜像URL。mirrors可以配置多个mirror,每个mirror有id,name,url,mirrorOf属性。

  • id是唯一标识一个mirror
  • name貌似没多大用,相当于描述
  • url是官方的库地址
  • mirrorOf代表了一个镜像的替代位置,例如central就表示代替官方的中央库。

mirror也不是按settings.xml中写的那样的顺序来查询的。所谓的第一个并不一定是最上面的那个。

当有id为B,A,C的顺序的mirror在mirrors节点中,maven会根据字母排序来指定第一个,所以不管怎么排列,一定会找到A这个mirror来进行查找,当A无法连接,出现意外的情况下,才会去B查询。

在setting·xml中添加如下代码:

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

maven替换中央仓库- 阿里云_第1张图片
image

第二种,分别给每个项目配置不同的中央库

直接在项目的pom.xml中修改中央库的地址。如下:


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

完整的pom:


    4.0.0
    com.xiaolyuh
    spring-boot-student
    0.0.1-SNAPSHOT
    pom
    spring-boot-student

    
    
        org.springframework.boot
        spring-boot-starter-parent
        1.5.3.RELEASE
         
    

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

    
    

    
        UTF-8
        UTF-8
        1.8
    

    
        
            org.springframework.boot
            spring-boot-starter
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    

    
        spring-boot-student-banner
    


你可能感兴趣的:(maven替换中央仓库- 阿里云)