Gradle 换阿里仓库

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiaolyuh123/article/details/83149428

改单个项目

在项目的build.gradle文件中,修改repositories配置,将mavenCentral()改为 maven{ url ‘http://maven.aliyun.com/nexus/content/groups/public/’}, 如:

repositories {
    maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
}

更改所有项目

如果想一次更改所有的仓库地址,可以在 USER_HOME/.gradle/文件夹下添加 init.gradle文件来配置,如:

allprojects{
    repositories {
        def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public/'
        all { ArtifactRepository repo ->
            if(repo instanceof MavenArtifactRepository){
                def url = repo.url.toString()
                if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com/')) {
                    remove repo
                }
            }
        }
        maven {
            url REPOSITORY_URL
        }
    }
}

猜你喜欢

转载自blog.csdn.net/xiaolyuh123/article/details/83149428