Last active
September 10, 2024 13:54
-
-
Save dongfg/30997b060068e962b40521d3921bc427 to your computer and use it in GitHub Desktop.
Gradle国内全局加速, 把这个文件放到~/.gradle目录下既可, tks https://gist.github.com/wuseal/76506684c63c5399150d9fd671cbc89b
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
@file:Suppress("UnstableApiUsage") | |
object AliYunMaven { | |
const val CENTRAL = "https://maven.aliyun.com/repository/central/" | |
const val JCENTER = "https://maven.aliyun.com/repository/jcenter/" | |
const val GOOGLE = "https://maven.aliyun.com/repository/google/" | |
const val GRADLE_PLUGIN = "https://maven.aliyun.com/repository/gradle-plugin/" | |
const val APACHE_SNAPSHOTS = "https://maven.aliyun.com/repository/apache-snapshots/" | |
} | |
settingsEvaluated { | |
pluginManagement { | |
repositories { | |
clear() | |
maven { url = uri(AliYunMaven.CENTRAL) } | |
maven { url = uri(AliYunMaven.JCENTER) } | |
maven { url = uri(AliYunMaven.GOOGLE) } | |
maven { url = uri(AliYunMaven.GRADLE_PLUGIN) } | |
maven { url = uri(AliYunMaven.APACHE_SNAPSHOTS) } | |
google() | |
mavenCentral() | |
gradlePluginPortal() | |
} | |
} | |
dependencyResolutionManagement { | |
repositories { | |
clear() | |
maven { url = uri(AliYunMaven.CENTRAL) } | |
maven { url = uri(AliYunMaven.JCENTER) } | |
maven { url = uri(AliYunMaven.GOOGLE) } | |
maven { url = uri(AliYunMaven.APACHE_SNAPSHOTS) } | |
google() | |
mavenCentral() | |
} | |
} | |
} | |
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(AliYunMaven.CENTRAL) | |
} | |
url.startsWith("https://jcenter.bintray.com/") -> { | |
setUrl(AliYunMaven.JCENTER) | |
} | |
url.startsWith("https://plugins.gradle.org/m2") -> { | |
setUrl(AliYunMaven.GRADLE_PLUGIN) | |
} | |
} | |
} | |
} | |
} | |
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(AliYunMaven.CENTRAL) | |
} | |
url.startsWith("https://jcenter.bintray.com/") -> { | |
setUrl(AliYunMaven.JCENTER) | |
} | |
url.startsWith("https://plugins.gradle.org/m2") -> { | |
setUrl(AliYunMaven.GRADLE_PLUGIN) | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gradle Wrapper 加速