gradle配置全局的自定义镜像
Gradle

在使用gradle的时候,我们会跟maven一样,去设置自定义的镜像仓库。那么以阿里云镜像为例,做一个全局配置。
在~/.gradle下创建一个init.gradle文件
内容如下

def repoConfig = {
    all { ArtifactRepository repo ->
        if (repo instanceof MavenArtifactRepository) {
            def url = repo.url.toString()
            if (url.contains('[repo1.maven.org/maven2](http://repo1.maven.org/maven2)') || url.contains('jcenter.bintray.com')) {
                println "gradle init: (${repo.name}: ${repo.url}) removed"
                remove repo
            }
        }
    }
    mavenLocal()
    maven { url '[https://maven.aliyun.com/repository/public](https://maven.aliyun.com/repository/public)' }
    maven { url '[https://maven.aliyun.com/repository/jcenter](https://maven.aliyun.com/repository/jcenter)' }
    maven { url '[https://maven.aliyun.com/repository/google](https://maven.aliyun.com/repository/google)' }
    maven { url '[https://maven.aliyun.com/repository/gradle-plugin](https://maven.aliyun.com/repository/gradle-plugin)' }
}

allprojects {
    buildscript {
        repositories repoConfig
    }

    repositories repoConfig
}
暂无评论