Last active
March 16, 2024 03:22
-
-
Save wuseal/76506684c63c5399150d9fd671cbc89b to your computer and use it in GitHub Desktop.
国内全局加速Gradle依赖下载速度配置,把这个文件放到~/.gradle目录下既可
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Seal.Wu on 2020/7/11 | |
* Description: Set up mirrors for Gradle Globally | |
*/ | |
val MAVEN_REPOSITORY_URL = "https://maven.aliyun.com/repository/central" | |
val JCENTER_REPOSITORY_URL = "https://maven.aliyun.com/repository/jcenter" | |
val GOOGLE_REPOSITORY_URL = "https://maven.aliyun.com/repository/google" | |
val GRADLE_PLUGIN_REPOSITORY_URL = "https://maven.aliyun.com/repository/gradle-plugin" | |
gradle.settingsEvaluated { | |
pluginManagement { | |
// Print repositories collection | |
println("Plugins Repositories names: " + repositories.names) | |
// Clear repositories collection | |
repositories.clear() | |
// Add my Artifactory mirror | |
repositories { | |
maven { | |
name = "Aly Gradle Plugin Repo" | |
url = uri(GRADLE_PLUGIN_REPOSITORY_URL) | |
} | |
} | |
// Print repositories collection | |
println("Now Plugins Repositories names : " + repositories.names) | |
} | |
} | |
allprojects { | |
repositories { | |
all { | |
if (this is MavenArtifactRepository) { | |
val url = url.toString() | |
when { | |
url.startsWith("https://repo1.maven.org/maven2")|| url.startsWith("https://repo.maven.apache.org/maven2/") -> { | |
setUrl(MAVEN_REPOSITORY_URL) | |
} | |
url.startsWith("https://jcenter.bintray.com/") -> { | |
setUrl(JCENTER_REPOSITORY_URL) | |
} | |
url.startsWith("https://dl.google.com/dl/android/maven2") -> { | |
setUrl(GOOGLE_REPOSITORY_URL) | |
} | |
} | |
} | |
} | |
} | |
buildscript { | |
repositories { | |
all { | |
if (this is MavenArtifactRepository) { | |
val url = this.url.toString() | |
when { | |
url.startsWith("https://repo1.maven.org/maven2")||url.startsWith("https://repo.maven.apache.org/maven2/") -> { | |
setUrl(MAVEN_REPOSITORY_URL) | |
} | |
url.startsWith("https://jcenter.bintray.com/") -> { | |
setUrl(JCENTER_REPOSITORY_URL) | |
} | |
url.startsWith("https://dl.google.com/dl/android/maven2") -> { | |
setUrl(GOOGLE_REPOSITORY_URL) | |
} | |
} | |
} | |
} | |
} | |
} | |
afterEvaluate { | |
repositories { | |
val lastUsedRepos = filterIsInstance<MavenArtifactRepository>().map { | |
it.name + "(${it.url})" | |
} | |
if (lastUsedRepos.isNotEmpty()) { | |
println("Use these repositories at last :\n $lastUsedRepos") | |
} | |
} | |
buildscript { | |
repositories { | |
val lastUsedRepos = filterIsInstance<MavenArtifactRepository>().map { | |
it.name + "(${it.url})" | |
} | |
if (lastUsedRepos.isNotEmpty()) { | |
println("Use these repositories at last in build script:\n $lastUsedRepos") | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
修复后的
`/**
*/
val MAVEN_REPOSITORY_URL = "https://maven.aliyun.com/repository/central"
val JCENTER_REPOSITORY_URL = "https://maven.aliyun.com/repository/jcenter"
val GOOGLE_REPOSITORY_URL = "https://maven.aliyun.com/repository/google"
val GRADLE_PLUGIN_REPOSITORY_URL = "https://maven.aliyun.com/repository/gradle-plugin"
gradle.settingsEvaluated {
pluginManagement {
// Print repositories collection
println("Plugins Repositories names: " + repositories.names)
}
allprojects {
repositories {
all {
if (this is MavenArtifactRepository) {
val url = url.toString()
when {
url.startsWith("https://repo1.maven.org/maven2")|| url.startsWith("https://repo.maven.apache.org/maven2/") -> {
setUrl(MAVEN_REPOSITORY_URL)
}
url.startsWith("https://jcenter.bintray.com/") -> {
setUrl(JCENTER_REPOSITORY_URL)
}
url.startsWith("https://dl.google.com/dl/android/maven2") -> {
setUrl(GOOGLE_REPOSITORY_URL)
}
}
}
}
}
buildscript {
repositories {
all {
if (this is MavenArtifactRepository) {
val url = this.url.toString()
when {
url.startsWith("https://repo1.maven.org/maven2")||url.startsWith("https://repo.maven.apache.org/maven2/") -> {
setUrl(MAVEN_REPOSITORY_URL)
}
url.startsWith("https://jcenter.bintray.com/") -> {
setUrl(JCENTER_REPOSITORY_URL)
}
url.startsWith("https://dl.google.com/dl/android/maven2") -> {
setUrl(GOOGLE_REPOSITORY_URL)
}
}
}
}
}
}
afterEvaluate {
repositories {
val lastUsedRepos = filterIsInstance().map {
it.name + "(${it.url})"
}
if (lastUsedRepos.isNotEmpty()) {
println("Use these repositories at last :\n $lastUsedRepos")
}
}
buildscript {
repositories {
val lastUsedRepos = filterIsInstance().map {
it.name + "(${it.url})"
}
if (lastUsedRepos.isNotEmpty()) {
println("Use these repositories at last in build script:\n $lastUsedRepos")
}
}
}
}
}`