如果Gradle
在编译的时候没有在本地仓库中发现依赖,就会从远程仓库中下载,默认的远程仓库为mavenCentral()
,也就是http://repo1.maven.org/maven2/,但是往往访问速度特别慢,不翻墙经常会下载超时或者需要很长时间导致Build失败,因此,可以用国内的仓库代替:
在项目的build.gradle
文件中,修改repositories
配置 由:
改为:
repositories { maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'} }或:
repositories { maven{ url 'http://maven.oschina.net/content/groups/public/'} }这样就可以从国内的镜像中下载依赖,速度能提高不少
如果想一次更改所有的仓库地址,可以在USER_HOME/.gradle/
(如C:/Users/hellowood/.gradle
)文件夹下添加init.gradle
文件来配置
这样就可以在项目编译的时候从阿里的仓库中下载依赖了
init.build
脚本可以参考https://docs.gradle.org/current/userguide/init_scripts.html新闻热点
疑难解答