gradle配置国内镜像

发布时间:2019年05月20日 阅读:316 次

gradle配置国内镜像

使用阿里云国内镜像

对单个项目生效,在项目中的build.gradle修改内容

复制代码
  1. buildscript {
  2.     repositories {
  3.         maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
  4.                 maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
  5.     }
  6.     dependencies {
  7.         classpath 'com.android.tools.build:gradle:2.2.3'
  8.  
  9.         // NOTE: Do not place your application dependencies here; they belong        // in the individual module build.gradle files    }        
  10. }
  11.  
  12. allprojects {
  13.     repositories {
  14.         maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
  15.         maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
  16.     }
  17. }
复制代码

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

复制代码
  1. allprojects{
  2.     repositories {
  3.         def ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'
  4.         def ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
  5.         all { ArtifactRepository repo ->            if(repo instanceof MavenArtifactRepository){
  6.                 def url = repo.url.toString()                if (url.startsWith('https://repo1.maven.org/maven2')) {
  7.                     project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
  8.                     remove repo
  9.                 }                if (url.startsWith('https://jcenter.bintray.com/')) {
  10.                     project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
  11.                     remove repo
  12.                 }
  13.             }
  14.         }
  15.         maven {
  16.                 url ALIYUN_REPOSITORY_URL
  17.             url ALIYUN_JCENTER_URL
  18.         }
  19.     }
  20. }


Tag:
相关文章

发表评论: