美文网首页
Gradle 阿里云仓库配置

Gradle 阿里云仓库配置

作者: nobigogle | 来源:发表于2022-04-26 15:41 被阅读0次

采用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
        }
    }
}

相关文章

网友评论

      本文标题:Gradle 阿里云仓库配置

      本文链接:https://www.haomeiwen.com/subject/vfxhyrtx.html