美文网首页
Maven阿里云代理库方案

Maven阿里云代理库方案

作者: 明训 | 来源:发表于2021-04-13 00:02 被阅读0次

    背景说明

    由于国内网络限制的原因导致maven官方仓库下载速度特别慢,甚至很多依赖下载不下来,maven.aliyun.com代理了很多公共的maven仓库。使用maven.aliyun.com中的仓库地址作为下载源,速度更快更稳定。

    使用指南

    https://help.aliyun.com/document_detail/102512.html?spm=a2c40.aliyun_maven_repo.0.0.36183054FeuIPW

    方案说明

    一般情况下在mavne项目中有两种依赖

    • maven构建依赖[dependency]
    • maven插件依赖[plugin]

    解决方案

    坐标查询

    https://maven.aliyun.com/mvn/search

    仓库浏览

    https://maven.aliyun.com/mvn/view

    Repository Type Policy Path
    apache snapshots proxy SNAPSHOT https://maven.aliyun.com/repository/apache-snapshots
    central proxy RELEASE https://maven.aliyun.com/repository/central
    google proxy RELEASE https://maven.aliyun.com/repository/google
    gradle-plugin proxy RELEASE https://maven.aliyun.com/repository/gradle-plugin
    jcenter proxy RELEASE https://maven.aliyun.com/repository/jcenter
    spring proxy RELEASE https://maven.aliyun.com/repository/spring
    spring-plugin proxy RELEASE https://maven.aliyun.com/repository/spring-plugin
    public group RELEASE https://maven.aliyun.com/repository/public
    releases hosted RELEASE https://maven.aliyun.com/repository/releases
    snapshots hosted SNAPSHOT https://maven.aliyun.com/repository/snapshots
    grails-core proxy RELEASE https://maven.aliyun.com/repository/grails-core
    mapr-public proxy RELEASE https://maven.aliyun.com/repository/mapr-public
    • proxy表示的是仓库代理
    • hosted表示是物理上的仓库,相当于是阿里的私服

    概念说明

    目前在网络上主流有两种配置方案

    第一种[主流]

    <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>        
    </mirror>
    
    • 表示把阿里的私服当做中央仓库来使用
    • 可以下载到阿里私服里面的相关依赖[即使没有推送到中央仓库]
    • 如果现有项目或业务强依赖阿里相关的组件,建议采用此种方案

    第二种

    <mirror>
        <id>alimaven-central</id>
        <mirrorOf>central</mirrorOf>
        <name>aliyun central</name>
        <url>https://maven.aliyun.com/repository/central</url>
    </mirror>
    
    • 表示使用阿里对中央仓库的代理进行使用

    • 可以下载到阿里推送到中央仓库相关依赖[没有推送到中央仓库的依赖无法下载]

    • 如果现有项目或业务强依赖没有阿里相关的组件,建议采用此种方案

    最佳实践

    dependency

    repositories

    repositories标签的作用是: 用来配置maven项目的远程仓库。

    <repositories>
        <repository>
            <id>aliyun</id>
            <url>https://maven.aliyun.com/repository/public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    
    mirror

    进入maven的安装目录找到settings.xmlmirrors节点下添加如下配置

        <mirror>
            <id>alimaven-central</id>
            <mirrorOf>central</mirrorOf>
            <name>aliyun central</name>
            <url>https://maven.aliyun.com/repository/central</url>
        </mirror>
        
        <mirror>
            <id>alimaven-google</id>
            <mirrorOf>google</mirrorOf>
            <name>aliyun maven google</name>
            <url>https://maven.aliyun.com/repository/google/</url>
        </mirror>
    
        <mirror>
            <id>alimaven-gradle-pluginr</id>
            <mirrorOf>gradle-plugin</mirrorOf>
            <name>aliyun maven gradle-plugin</name>
            <url>https://maven.aliyun.com/repository/gradle-plugin/</url>
        </mirror>
    
        <mirror>
            <id>alimaven-jcenter</id>
            <mirrorOf>jcenter</mirrorOf>
            <name>aliyun maven jcenter</name>
            <url>https://maven.aliyun.com/repository/jcenter/</url>
        </mirror>
    
        <mirror>
            <id>alimaven-spring</id>
            <mirrorOf>spring</mirrorOf>
            <name>aliyun maven spring</name>
            <url>https://maven.aliyun.com/repository/spring/</url>
        </mirror>
    
        <mirror>
            <id>alimaven-spring-plugin</id>
            <mirrorOf>spring-plugin</mirrorOf>
            <name>aliyun maven spring-plugin</name>
            <url>https://maven.aliyun.com/repository/spring-plugin/</url>
        </mirror>
    
        <mirror>
            <id>alimaven-grails-core</id>
            <mirrorOf>grails-core</mirrorOf>
            <name>aliyun maven grails-core</name>
            <url>https://maven.aliyun.com/repository/grails-core/</url>
        </mirror>
    
        <mirror>
            <id>alimaven-mapr-public</id>
            <mirrorOf>mapr-public</mirrorOf>
            <name>aliyun maven mapr-public</name>
            <url>https://maven.aliyun.com/repository/mapr-public/</url>
        </mirror>
    

    jar依赖从阿里云下载

    plugin

    pluginRepository标签的作用是: 用来配置maven插件的远程仓库,找到项目的pom.xml配置,添加如下配置

    <pluginRepositories>
        <pluginRepository>
            <id>alimaven-central</id>
            <name>aliyun central</name>
            <url>https://maven.aliyun.com/repository/central</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>alimaven-jcenter</id>
            <name>aliyun jcenter</name>
            <url>https://maven.aliyun.com/repository/jcenter</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>alimaven-spring</id>
            <name>aliyun spring</name>
            <url>https://maven.aliyun.com/repository/spring</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
    
    • plugin依赖从阿里云下载

    快速配置

    <repositories>
        <repository>
            <id>aliyun</id>
            <url>https://maven.aliyun.com/repository/public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>aliyun-plugin</id>
            <url>https://maven.aliyun.com/repository/public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
    

    相关文章

      网友评论

          本文标题:Maven阿里云代理库方案

          本文链接:https://www.haomeiwen.com/subject/mjqzkltx.html