更改Gradle镜像下载地址
生活随笔
收集整理的這篇文章主要介紹了
更改Gradle镜像下载地址
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 全局更改Gradle鏡像下載地址
- 單項目更改Gradle鏡像下載地址
全局更改Gradle鏡像下載地址
如果配置GRADLE_USER_HOME路徑則在${GRADLE_USER_HOME}下新建init.gradle文件
如果沒有配置則在默認路徑${USER_HOME}/.gradle/下新建init.gradle文件。
init.gradle文件內容如下:
allprojects {repositories {def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/public'def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter'def ALIYUN_GOOGLE_URL = 'https://maven.aliyun.com/repository/google'def ALIYUN_GRADLE_PLUGIN_URL = 'https://maven.aliyun.com/repository/gradle-plugin'def ALIYUN_GRAILS_CORE = 'https://maven.aliyun.com/repository/grails-core'def REPOSITORY_URL = 'https://repo1.maven.org/maven2/'def JCENTER_URL = 'https://jcenter.bintray.com/'def GOOGLE_URL = 'https://dl.google.com/dl/android/maven2/'def GRADLE_PLUGIN_URL = 'https://plugins.gradle.org/m2/'all { ArtifactRepository repo ->if (repo instanceof MavenArtifactRepository) {def url = repo.url.toString()if (url.startsWith(REPOSITORY_URL)) {project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."remove repo}if (url.startsWith(JCENTER_URL)) {project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."remove repo}if (url.startsWith(GOOGLE_URL)) {project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_GOOGLE_URL."remove repo}if (url.startsWith(GRADLE_PLUGIN_URL)) {project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_GRADLE_PLUGIN_URL."remove repo}}}maven { url ALIYUN_REPOSITORY_URL }maven { url ALIYUN_JCENTER_URL }maven { url ALIYUN_GOOGLE_URL }maven { url ALIYUN_GRADLE_PLUGIN_URL }maven { url ALIYUN_GRAILS_CORE }maven { url REPOSITORY_URL }maven { url JCENTER_URL }maven { url GOOGLE_URL }maven { url GRADLE_PLUGIN_URL }} }單項目更改Gradle鏡像下載地址
在project下的build.gradle文件中的buildscript節點和allprojects節點中的repositories補充如下內容
mavenLocal() maven { url 'https://maven.aliyun.com/repository/public' } maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } maven { url 'https://maven.aliyun.com/repository/grails-core' } google()完整build.gradle示例
buildscript {repositories {mavenLocal()maven { url 'https://maven.aliyun.com/repository/public' }maven { url 'https://maven.aliyun.com/repository/jcenter' }maven { url 'https://maven.aliyun.com/repository/google' }maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }maven { url 'https://maven.aliyun.com/repository/grails-core' }google()}dependencies {classpath 'com.android.tools.build:gradle:3.3.1'classpath "io.objectbox:objectbox-gradle-plugin:2.3.4"// NOTE: Do not place your application dependencies here; they belong// in the individual module build.gradle files} }allprojects {repositories {mavenLocal()maven { url 'https://maven.aliyun.com/repository/public' }maven { url 'https://maven.aliyun.com/repository/jcenter' }maven { url 'https://maven.aliyun.com/repository/google' }maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }maven { url 'https://maven.aliyun.com/repository/grails-core' }google()} }task clean(type: Delete) {delete rootProject.buildDir }總結
以上是生活随笔為你收集整理的更改Gradle镜像下载地址的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 混沌图像---蔡氏电路的漩涡
- 下一篇: 类设计者的核查表(转自C++rumina