Gradle在國(guó)內(nèi)配置鏡像加速的實(shí)現(xiàn)步驟
引言
在國(guó)內(nèi)使用 Gradle 構(gòu)建項(xiàng)目時(shí),最大的痛點(diǎn)就是 依賴下載賊慢,甚至卡死。下面教你如何 配置國(guó)內(nèi)鏡像加速 Gradle 下載依賴,主要是通過(guò)改寫 repositories 中的源地址來(lái)實(shí)現(xiàn)。親測(cè)有效。
一、修改 build.gradle 或 settings.gradle 的 repositories 配置
把默認(rèn)的 jcenter()
、mavenCentral()
或 google()
替換成國(guó)內(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.gradle
Windows:
C:\Users\<你的用戶名>\.gradle\init.gradle
內(nèi)容如下(自動(dòng)全局替換 Maven 倉(cāng)庫(kù)為阿里云):
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源”,你原來(lái) 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è)倉(cāng)庫(kù) URL,如果是 aliyun.com
或 tuna.tsinghua.edu.cn
就說(shuō)明成功了。
到此這篇關(guān)于Gradle在國(guó)內(nèi)配置鏡像加速的實(shí)現(xiàn)步驟的文章就介紹到這了,更多相關(guān)Gradle國(guó)內(nèi)配置鏡像加速內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java springboot接口迅速上手,帶你半小時(shí)極速入門
這篇文章主要給大家介紹了關(guān)于SpringBoot實(shí)現(xiàn)API接口的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-09-09如何設(shè)置springboot禁止日志輸出到控制臺(tái)
文章總結(jié):本文主要介紹了SpringBoot項(xiàng)目中使用SLF4J記錄日志時(shí),日志默認(rèn)輸出到控制臺(tái)的原因及解決方法,日志框架如Logback默認(rèn)會(huì)將日志輸出到控制臺(tái),可以通過(guò)`logback-spring.xml`配置文件或配置類來(lái)禁止日志輸出到控制臺(tái),并設(shè)置日志輸出級(jí)別2025-01-01利用spring?boot+WebSocket實(shí)現(xiàn)后臺(tái)主動(dòng)消息推送功能
目前對(duì)于服務(wù)端向客戶端推送數(shù)據(jù),常用技術(shù)方案有輪詢、websocket等,下面這篇文章主要給大家介紹了關(guān)于利用spring?boot+WebSocket實(shí)現(xiàn)后臺(tái)主動(dòng)消息推送功能的相關(guān)資料,需要的朋友可以參考下2022-04-04關(guān)于servlet向mysql添加數(shù)據(jù)時(shí)中文亂碼問(wèn)題的解決
最近在工作中遇到一個(gè)小問(wèn)題,出現(xiàn)了中文亂碼的問(wèn)題,無(wú)奈只能想辦法解決,下面這篇文章主要給大家介紹了關(guān)于servlet向mysql添加數(shù)據(jù)時(shí)中文亂碼問(wèn)題的解決方法,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來(lái)一起看看吧。2017-08-08