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
  • 相关阅读:
    div+css与table布局
    自动刷新网页效果
    Spring框架之Filter应用,filter可以使用spring注入资源
    http://localhost:8080/hohode
    java jacob 操作word 文档,进行写操作,如生成表格,添加 图片(这个不错,可以拿来直接用,非常好)
    java 填充word中的表格
    360抢票
    easyui 时间段校验,开始时间小于结束时间,并且时间间隔不能超过30天
    java操作word示例
    FastStone Capture 注册码 序列号
  • 原文地址:https://www.cnblogs.com/jukan/p/7197018.html
Copyright © 2011-2022 走看看