Gradle在國內(nèi)配置鏡像加速的實現(xiàn)步驟
引言
在國內(nèi)使用 Gradle 構(gòu)建項目時,最大的痛點(diǎn)就是 依賴下載賊慢,甚至卡死。下面教你如何 配置國內(nèi)鏡像加速 Gradle 下載依賴,主要是通過改寫 repositories 中的源地址來實現(xiàn)。親測有效。
一、修改 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/' } }
二、修改全局配置(推薦用于多項目)
如果你不想每個項目都寫一次,可以配置到全局:
路徑:
Linux / macOS:
~/.gradle/init.gradle
Windows:
C:\Users\<你的用戶名>\.gradle\init.gradle
內(nèi)容如下(自動全局替換 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') } } } } }
這樣就能實現(xiàn)“偷偷地?fù)Q源”,你原來 build.gradle
里啥都不用動。
三、代理加速(配合魔法使用)
在 ~/.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
可以看到使用了哪個倉庫 URL,如果是 aliyun.com
或 tuna.tsinghua.edu.cn
就說明成功了。
到此這篇關(guān)于Gradle在國內(nèi)配置鏡像加速的實現(xiàn)步驟的文章就介紹到這了,更多相關(guān)Gradle國內(nèi)配置鏡像加速內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java springboot接口迅速上手,帶你半小時極速入門
這篇文章主要給大家介紹了關(guān)于SpringBoot實現(xiàn)API接口的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-09-09利用spring?boot+WebSocket實現(xiàn)后臺主動消息推送功能
目前對于服務(wù)端向客戶端推送數(shù)據(jù),常用技術(shù)方案有輪詢、websocket等,下面這篇文章主要給大家介紹了關(guān)于利用spring?boot+WebSocket實現(xiàn)后臺主動消息推送功能的相關(guān)資料,需要的朋友可以參考下2022-04-04關(guān)于servlet向mysql添加數(shù)據(jù)時中文亂碼問題的解決
最近在工作中遇到一個小問題,出現(xiàn)了中文亂碼的問題,無奈只能想辦法解決,下面這篇文章主要給大家介紹了關(guān)于servlet向mysql添加數(shù)據(jù)時中文亂碼問題的解決方法,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。2017-08-08