国内maven太慢,用全局代理替换成阿里云的源

配置

路径:~/.gradle/init.gradle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
allprojects{
buildscript {
repositories {
def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/google'
def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter'
all { ArtifactRepository repo ->
if(repo instanceof MavenArtifactRepository){
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2')||url.startsWith('https://dl.google.com/dl/android/maven2')||url.startsWith('https://maven.google.com')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
remove repo
}
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
remove repo
}
}
}
maven {
url ALIYUN_REPOSITORY_URL
}
maven{
url ALIYUN_JCENTER_URL
}
}
}
repositories {
def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/google'
def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter'
all { ArtifactRepository repo ->
if(repo instanceof MavenArtifactRepository){
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2')||url.startsWith('https://dl.google.com/dl/android/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
remove repo
}
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
remove repo
}
}
}
maven {
url ALIYUN_REPOSITORY_URL
}
maven{
url ALIYUN_JCENTER_URL
}
}
}