Gradle 阿里云仓库配置

2022-04-26  本文已影响0人  nobigogle

采用Gradle有时需要下载外网的依赖,存在下载不到的情况,因此这里记录一下解决方式,将init.gradle文件放置在如下文件夹:

C:\Users\User-Name\.gradle

文件内容

allprojects{
    repositories {
        def ALIYUN_CENTRAL_URL = 'https://maven.aliyun.com/repository/central'
        def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/repository/public'
        def ALIYUN_GOOGLE_URL = 'https://maven.aliyun.com/repository/google'
        def ALIYUN_GRADLE_PLUGIN_URL = 'https://maven.aliyun.com/repository/gradle-plugin'
        def ALIYUN_SPRING_URL = 'https://maven.aliyun.com/repository/spring'
        def ALIYUN_SPRING_PLUGIN_URL = 'https://maven.aliyun.com/repository/spring-plugin'
        def ALIYUN_GRAILS_CORE_URL = 'https://maven.aliyun.com/repository/grails-core'
        def ALIYUN_APACHE_SNAPSHOT_URL = 'https://maven.aliyun.com/repository/apache-snapshots'

        all { ArtifactRepository repo ->
            if(repo instanceof MavenArtifactRepository){
                def url = repo.url.toString()
                if (url.startsWith('https://repo1.maven.org/maven2')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
                    remove repo
                }
                if (url.startsWith('https://jcenter.bintray.com/')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
                    remove repo
                }
            }
        }
        maven {
            url ALIYUN_CENTRAL_URL
            url ALIYUN_JCENTER_URL
            url ALIYUN_GOOGLE_URL
            url ALIYUN_GRADLE_PLUGIN_URL
            url ALIYUN_SPRING_URL
            url ALIYUN_SPRING_PLUGIN_URL
            url ALIYUN_GRAILS_CORE_URL
            url ALIYUN_APACHE_SNAPSHOT_URL
        }
    }
}
上一篇下一篇

猜你喜欢

热点阅读