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