zoukankan      html  css  js  c++  java
  • JCenter下载太慢?教你修改Maven仓库地址为国内镜像

    http://blog.csdn.net/biezhihua/article/details/49668605

    转载自:http://www.yrom.net/blog/2015/02/07/change-gradle-maven-repo-url/

    近来迁移了一些项目到Android Studio,采用Gradle构建确实比原来的Ant方便许多。但是编译时下载依赖的网速又着实令人蛋疼不已。

    如果能切换到国内的Maven镜像仓库,如开源中国的Maven库,又或者是换成自建的Maven私服,那想必是极好的。

    一个简单的办法,修改项目根目录下的build.gradle,将jcenter()或者mavenCentral()替换掉即可:

    allprojects {
        repositories {
            maven{ url 'http://maven.oschina.net/content/groups/public/'}
        }
    }
    • 1
    • 2
    • 3
    • 4
    • 5
    • 1
    • 2
    • 3
    • 4
    • 5

    但是架不住项目多,难不成每个都改一遍么? 
    自然是有省事的办法,将下面这段Copy到名为init.gradle文件中,并保存到USER_HOME/.gradle/文件夹下即可。

    allprojects{
        repositories {
            def REPOSITORY_URL = 'http://maven.oschina.net/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/')) {
                        project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
                        remove repo
                    }
                }
            }
            maven {
                url REPOSITORY_URL
            }
        }
    }
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    init.gradle文件其实是Gradle的初始化脚本(Initialization Scripts),也是运行时的全局配置。

    如果碰到如下错误,多尝试几次就好了:

    FAILURE: Build failed with an exception.
    
    * What went wrong:
    A problem occurred configuring root project 'fresco'.
    > Could not resolve all dependencies for configuration ':classpath'.
       > Could not download httpcore.jar (org.apache.httpcomponents:httpcore:4.1)
          > Could not get resource 'https://jcenter.bintray.com/org/apache/httpcomponents/httpcore/4.1/httpcore-4.1.jar'.
             > SSL peer shut down incorrectly
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    
    BUILD FAILED
  • 相关阅读:
    初识 Umbraco CQ
    程序员的利器SourceInsight CQ
    关于Hg的文件过滤 CQ
    蓝桥杯 基本内容
    leedswriting符号
    tiny mission 2021 11 15
    拓扑排序+二分答案+建图
    mission 11.24
    高数积分求面积
    高数积分求弧长
  • 原文地址:https://www.cnblogs.com/jukan/p/7197018.html
Copyright © 2011-2022 走看看