Gradle在國內(nèi)配置鏡像加速的實(shí)現(xiàn)步驟
引言
在國內(nèi)使用 Gradle 構(gòu)建項(xiàng)目時(shí),最大的痛點(diǎn)就是 依賴下載賊慢,甚至卡死。下面教你如何 配置國內(nèi)鏡像加速 Gradle 下載依賴,主要是通過改寫 repositories 中的源地址來實(shí)現(xiàn)。親測(cè)有效。
一、修改 build.gradle 或 settings.gradle 的 repositories 配置
把默認(rèn)的 jcenter()、mavenCentral() 或 google() 替換成國內(nèi)鏡像,比如阿里云或清華。
示例:使用阿里云加速
repositories {
maven { url 'https://maven.aliyun.com/repository/public' } // Maven Central
maven { url 'https://maven.aliyun.com/repository/jcenter' } // JCenter
maven { url 'https://maven.aliyun.com/repository/google' } // Google
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } // Gradle 插件
}或者使用清華鏡像(也比較穩(wěn)定)
repositories {
maven { url 'https://mirrors.tuna.tsinghua.edu.cn/maven/central/' }
maven { url 'https://mirrors.tuna.tsinghua.edu.cn/gradle/' }
}二、修改全局配置(推薦用于多項(xiàng)目)
如果你不想每個(gè)項(xiàng)目都寫一次,可以配置到全局:
路徑:
Linux / macOS:
~/.gradle/init.gradleWindows:
C:\Users\<你的用戶名>\.gradle\init.gradle
內(nèi)容如下(自動(dòng)全局替換 Maven 倉庫為阿里云):
allprojects {
repositories {
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.contains('jcenter.bintray.com')) {
repo.setUrl('https://maven.aliyun.com/repository/jcenter')
}
if (url.contains('mavenCentral')) {
repo.setUrl('https://maven.aliyun.com/repository/central')
}
if (url.contains('plugins.gradle.org')) {
repo.setUrl('https://maven.aliyun.com/repository/gradle-plugin')
}
if (url.contains('dl.google.com')) {
repo.setUrl('https://maven.aliyun.com/repository/google')
}
}
}
}
}這樣就能實(shí)現(xiàn)“偷偷地?fù)Q源”,你原來 build.gradle 里啥都不用動(dòng)。
三、代理加速(配合魔法使用)
在 ~/.gradle/gradle.properties 文件中加上代理設(shè)置:
systemProp.http.proxyHost=127.0.0.1 systemProp.http.proxyPort=7890 systemProp.https.proxyHost=127.0.0.1 systemProp.https.proxyPort=7890
你也可以使用環(huán)境變量配置:
export GRADLE_OPTS="-Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=7890 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=7890"
檢查是否生效
執(zhí)行構(gòu)建命令并加上 --info,例如:
./gradlew build --info
可以看到使用了哪個(gè)倉庫 URL,如果是 aliyun.com 或 tuna.tsinghua.edu.cn 就說明成功了。
到此這篇關(guān)于Gradle在國內(nèi)配置鏡像加速的實(shí)現(xiàn)步驟的文章就介紹到這了,更多相關(guān)Gradle國內(nèi)配置鏡像加速內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java中equals()知識(shí)點(diǎn)總結(jié)
在本篇文章里小編給大家分享的是關(guān)于Java中equals()知識(shí)點(diǎn)總結(jié)內(nèi)容,需要的朋友們可以學(xué)習(xí)參考下。2020-03-03
詳解java調(diào)用存儲(chǔ)過程并封裝成map
這篇文章主要介紹了詳解java調(diào)用存儲(chǔ)過程并封裝成map的相關(guān)資料,希望通過本文能幫助到大家實(shí)現(xiàn)這樣的功能,需要的朋友可以參考下2017-09-09
Spring MVC中使用Google kaptcha驗(yàn)證碼的方法詳解
kaptcha 是一個(gè)非常實(shí)用的驗(yàn)證碼生成工具。有了它,你可以生成各種樣式的驗(yàn)證碼,因?yàn)樗强膳渲玫?,下面這篇文章主要給大家介紹了關(guān)于Spring MVC中使用Google kaptcha驗(yàn)證碼的方法,需要的朋友可以參考借鑒,下面來一起看看吧。2017-10-10
Spring boot整合mybatis實(shí)現(xiàn)過程圖解
這篇文章主要介紹了Spring boot整合mybatis實(shí)現(xiàn)過程圖解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-08-08
Springboot jdbctemplate整合實(shí)現(xiàn)步驟解析
這篇文章主要介紹了Springboot jdbctemplate整合實(shí)現(xiàn)步驟解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-08-08
如何解決報(bào)錯(cuò):java.net.BindException:無法指定被請(qǐng)求的地址問題
在Linux虛擬機(jī)上安裝并啟動(dòng)Tomcat時(shí)遇到啟動(dòng)失敗的問題,通過檢查端口及配置文件未發(fā)現(xiàn)異常,后發(fā)現(xiàn)/etc/hosts文件中缺少localhost的映射,添加后重啟Tomcat成功,Tomcat啟動(dòng)時(shí)會(huì)檢查localhost的IP映射,缺失或錯(cuò)誤都可能導(dǎo)致啟動(dòng)失敗2024-10-10
淺談hibernate急迫加載問題(多重外鍵關(guān)聯(lián))
這篇文章主要介紹了淺談hibernate急迫加載問題(多重外鍵關(guān)聯(lián)),具有一定借鑒價(jià)值,需要的朋友可以參考下。2017-12-12

