Gradle配置国内镜像

匿名 (未验证) 提交于 2019-12-02 23:43:01

使用阿里云国内镜像

单个项目配置,在项目中的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'}     } } 

全局配置,对所有项目生效,在USER_HOME/.gradle/下创建init.gradle文件

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')) {                     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             url ALIYUN_JCENTER_URL         }     } } 

转载于:https://my.oschina.net/u/3655450/blog/1631136

文章来源: https://blog.csdn.net/weixin_33750452/article/details/92397641
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!