gradle配置国内镜像
原创
©著作权归作者所有:来自51CTO博客作者周成乐的原创作品,请联系作者获取转载授权,否则将追究法律责任
对单个项目生效,在项目中的build.gradle修改内容
buildscript {
repositories {
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
}
}
配置/etc/profile
export GRADLE_HOME=/mnt/sda4/zcl/third/gradle-4.5.1
export PATH=${GRADLE_HOME}/bin:${PATH}
export GRADLE_USER_HOME=/mnt/sda4/zcl/third/gradle-4.5.1/.gradle
source /etc/profile
对所有项目生效,在USER_HOME/.gradle/下创建init.gradle文件
allprojects{
repositories {
def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public/'
all { ArtifactRepository repo ->
if(repo instanceof MavenArtifactRepository){
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
remove repo
}
}
}
maven {
url REPOSITORY_URL
}
}
}