天天看點

常用Maven庫,鏡像庫及maven/gradle配置

平時用到的庫

倉庫名 位址 備注
mavenCentral

https://repo1.maven.org/maven2/

https://repo.maven.apache.org/maven2/

全區最大的maven庫,第二個為apache的鏡像庫, gradle預設位址
jcenter https://jcenter.bintray.com/anverus/tools/ bintray私有庫 相容mavenCentral中心倉庫,且性能更優
google https://dl.google.com/dl/android/maven2/ google私有庫
jitpack https://www.jitpack.io 自動建構庫github,及其他git 項目,自帶cdn加速
mavenLocal ~/.m2/repository 本地倉庫
Spring https://repo.spring.io/libs-milestone//anverus/tools/ Java Spring庫,包含于jcenter/mavenCentral
Spring Plugins https://repo.spring.io/plugins-release/ Java Spring 插件庫,包含于jcenter/mavenCentral

國内阿裡雲鏡像庫

倉庫名稱 代理源位址 使用位址
central https://repo1.maven.org/maven2/ https://maven.aliyun.com/repository/central
jcenter http://jcenter.bintray.com/ https://maven.aliyun.com/repository/jcenter
public central/jcenter 聚合倉 https://maven.aliyun.com/repository/public
google https://maven.google.com/ https://maven.aliyun.com/repository/google
gradle-plugin https://plugins.gradle.org/m2/ https://maven.aliyun.com/repository/gradle-plugin
spring http://repo.spring.io/libs-milestone/ https://maven.aliyun.com/repository/spring
spring-plugin http://repo.spring.io/plugins-release/ https://maven.aliyun.com/repository/spring-plugin

加速配置

将central/jcenter/google 換成阿裡雲位址即可

maven配置

打開maven的配置檔案(windows機器一般在maven安裝目錄的conf/settings.xml),在

<mirrors></mirrors>

标簽添加mirror子節點:

<mirror>
    <id>aliyunmaven</id>
    <mirrorOf>*</mirrorOf>
    <name>阿裡雲公共倉庫</name>
    <url>https://maven.aliyun.com/repository/public</url>
</mirror>
           

如果想使用其它代理倉庫,可在

<repositories></repositories>

節點中加入對應的倉庫使用位址。以使用google代理倉為例:

<repository>
    <id>spring</id>
    <url>https://maven.aliyun.com/repository/google</url>
    <releases>
        <enabled>true</enabled>
    </releases>
    <snapshots>
        <enabled>true</enabled>
    </snapshots>
</repository>
           

gradle配置

在build.gradle檔案中加入以下代碼:

allprojects {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/public/' }
        maven { url 'https://maven.aliyun.com/repository/google/' }
        // 阿裡的同步實時性較差,如果想要使用最新版本的,建議再加上 google()
        google()
        mavenLocal()
    }
}
           

參考

maven repo排名

阿裡雲效文檔

阿裡雲repositories 一覽

繼續閱讀