zoukankan      html  css  js  c++  java
  • 使用代理仓储init.gradle

    def oldRepos = [
            // central
            "https://repo1.maven.org/maven2/",
            // jcenter
            "https://jcenter.bintray.com/",
            // google
            "https://maven.google.com/",
            "https://dl.google.com/dl/android/maven2/",
            // gradle-plugin
            "https://plugins.gradle.org/m2/",
    ]
    
    def newRepos = [
            // central仓和jcenter仓的聚合仓
            "https://maven.aliyun.com/repository/public",
            // https://maven.google.com/
            "https://maven.aliyun.com/repository/google",
            // https://plugins.gradle.org/m2/
            "https://maven.aliyun.com/repository/gradle-plugin",
    ]
    
    
    def repoConfigClosure = { String name ->
        all { ArtifactRepository repo ->
            if (repo instanceof MavenArtifactRepository) {
                def url = repo.url.toString()
                if (oldRepos.contains(url)) {
                    println "gradle init, $name : (${repo.name}: ${repo.url}) removed"
                    remove repo
                }
            }
        }
    
        for (String url in newRepos) {
            maven {
                it.url url
            }
        }
    }
    
    allprojects {
        buildscript {
            repositories {
                repoConfigClosure.delegate = it
                repoConfigClosure("buildscript")
            }
        }
    
        repositories {
            repoConfigClosure.delegate = it
            repoConfigClosure(project.name)
        }
    }
    
    gradle.taskGraph.afterTask { Task task ->
        if (task.name.startsWith("assemble")) {
            def sb = new StringBuilder("All repos:
    ")
            sb.append("buildscript.repositories:
    ")
    
            gradle.getRootProject().buildscript.repositories.each {
                sb.append(it.name)
                if (it instanceof MavenArtifactRepository) {
                    sb.append(" : " + it.url)
                }
                sb.append("
    ")
            }
    
            sb.append("project.repositories:
    ")
            gradle.getRootProject().repositories.each {
                sb.append(it.name)
                if (it instanceof MavenArtifactRepository) {
                    sb.append(" : " + it.url)
                }
                sb.append("
    ")
            }
            println sb
        }
    }
  • 相关阅读:
    基于antlr的表达式解析器
    ANTLR语法层的选项及动作
    Understanding ANTLR Grammar Files
    写给Git初学者的7个建议
    Top 8 Diagrams for Understanding Java
    技术面不深入
    一个初级程序员学习新技术的策略
    SoftReference,WeakReference&WeakHashMap
    探索Antlr(Antlr 3.0更新版)
    Five minute introduction to ANTLR 3
  • 原文地址:https://www.cnblogs.com/muouren/p/13949465.html
Copyright © 2011-2022 走看看