解决gradle下载慢的问题

Posted wang2804355025

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决gradle下载慢的问题相关的知识,希望对你有一定的参考价值。

到~/.gradle/目录下创建一个 init.gradle 文件,把下面这些复制进去就 ok 了
allprojects{
repositories {
def ALIYUN_REPOSITORY_URL = ‘http://maven.aliyun.com/nexus/content/groups/public‘
def ALIYUN_JCENTER_URL = ‘http://maven.aliyun.com/nexus/content/repositories/jcenter‘
all { ArtifactRepository repo ->
if(repo instanceof MavenArtifactRepository){
def url = repo.url.toString()
if (url.startsWith(‘https://repo1.maven.org/maven2‘) || url.startsWith(‘http://repo1.maven.org/maven2‘)) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
remove repo
}
if (url.startsWith(‘https://jcenter.bintray.com/‘) || url.startsWith(‘http://jcenter.bintray.com/‘)) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
remove repo
}
}
}
maven {
url ALIYUN_REPOSITORY_URL
url ALIYUN_JCENTER_URL
}
}


buildscript{
repositories {
def ALIYUN_REPOSITORY_URL = ‘http://maven.aliyun.com/nexus/content/groups/public‘
def ALIYUN_JCENTER_URL = ‘http://maven.aliyun.com/nexus/content/repositories/jcenter‘
all { ArtifactRepository repo ->
if(repo instanceof MavenArtifactRepository){
def url = repo.url.toString()
if (url.startsWith(‘https://repo1.maven.org/maven2‘) || url.startsWith(‘http://repo1.maven.org/maven2‘)) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
remove repo
}
if (url.startsWith(‘https://jcenter.bintray.com/‘) || url.startsWith(‘http://jcenter.bintray.com/‘)) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
remove repo
}
}
}
maven {
url ALIYUN_REPOSITORY_URL
url ALIYUN_JCENTER_URL
}
}
}
}

以上是关于解决gradle下载慢的问题的主要内容,如果未能解决你的问题,请参考以下文章

解决gradle下载慢的问题

快速解决 GRADLE 项目下载 gradle-*-all.zip 慢的问题

完美解决gradle下载慢的问题

gradle 下载慢的问题解决

解决AS gradle下载同步卡慢的问题

Gradle: Download 下载慢的解决办法