/AliyunGradleConfig

在天朝使用jcenter、mavenCentral及google三个远程仓库,Gradle Sync太慢?一招教你配置阿里云镜像源。init.d/init.gradle

Primary LanguageBatchfileMIT LicenseMIT

在天朝使用jcenter、mavenCentral及google三个远程仓库,Gradle Sync会很慢,google仓库甚至需要科学上网才能访问。为了加快Gradle Sync速度,一招教你优先用 阿里云仓库服务 的仓库作为下载源。 LICENSE

一劳永逸之道

将本项目的grdadle/init.d/init.gradle复制到USER_HOME/.gradle/下即可。 USER_HOME在Windows上大约为C:/Users/liyujiang/.gradle/,在Linux上大约为/home/liyujiang/.gradle/
init.d/init.gradle内容为:

buildscript {
    repositories {
        maven{ url 'https://maven.aliyun.com/repository/public'}
        maven { url 'https://maven.aliyun.com/repositories/jcenter' }
        maven { url 'https://maven.aliyun.com/repositories/google' }
        maven { url 'https://maven.aliyun.com/repository/central' }
    }
}
    
allprojects {
    repositories {
        maven{ url 'https://maven.aliyun.com/repository/public'}
        maven { url 'https://maven.aliyun.com/repositories/jcenter' }
        maven { url 'https://maven.aliyun.com/repositories/google' }
        maven { url 'https://maven.aliyun.com/repository/central' }
        maven { url "https://jitpack.io" }
    }
}

Maven仓库列表

仓库名 简介 实际地址 使用地址
jcenter JFrog公司提供的仓库 http://jcenter.bintray.com https://maven.aliyun.com/repository/jcenter
https://maven.aliyun.com/nexus/content/repositories/jcenter
mavenLocal 本台电脑上的仓库 {USER_HOME}/.m2/repository C:/Users/liyujiang/.m2/repository (Windows)
/home/liyujiang/.m2/repository (Linux)
mavenCentral Sonatype公司提供的**库 http://central.maven.org/maven2 https://maven.aliyun.com/repository/central
https://maven.aliyun.com/nexus/content/repositories/central
google Google公司提供的仓库 https://maven.google.com https://maven.aliyun.com/repository/google
https://maven.aliyun.com/nexus/content/repositories/google
https://dl.google.com/dl/android/maven2
jitpack JitPack提供的仓库 https://jitpack.io https://jitpack.io
public jcenter和mavenCentral的聚合仓库 https://maven.aliyun.com/repository/public
https://maven.aliyun.com/nexus/content/groups/public
gradle-plugin Gradle插件仓库 https://plugins.gradle.org/m2 https://maven.aliyun.com/repository/gradle-plugin
https://maven.aliyun.com/nexus/content/repositories/gradle-plugin

阿里云镜像源配置

在项目根目录下的build.gradleallprojects.repositories闭包内的最前面添加阿里云的仓库地址:

buildscript {
    repositories {
        jcenter()
        google()
    }
}

allprojects {
    repositories {
        maven {
            url 'https://maven.aliyun.com/repository/jcenter'
        }
        maven {
            url 'https://maven.aliyun.com/repository/central'
        }
        maven {
            url 'https://maven.aliyun.com/repository/google'
        }
        jcenter()
        mavenCentral()
        google()
    }
}

项目模板文件介绍

  • .gitignore 通用的Gradle项目版本控制文件忽略规则
  • .travis.yml Github项目的特拉维斯持续集成配置
  • app/proguard-rules.pro 通用的混淆规则
  • build.gradle Gradle项目构建管理
  • publish.gradle Gradle项目发布到Maven仓库及上传到jcenter
  • version.gradle Gradle项目依赖项版本统一管理
  • publishToMavenLocal.cmd 一键执行发布Gradle项目到本地的Maven仓库
  • bintrayUpload.cmd 一键执行上传已发布到本地Maven仓库的项目到jcenter