Skip to content

Instantly share code, notes, and snippets.

@dongfg
Last active September 10, 2024 13:54
Show Gist options
  • Save dongfg/30997b060068e962b40521d3921bc427 to your computer and use it in GitHub Desktop.
Save dongfg/30997b060068e962b40521d3921bc427 to your computer and use it in GitHub Desktop.
Gradle国内全局加速, 把这个文件放到~/.gradle目录下既可, tks https://gist.github.com/wuseal/76506684c63c5399150d9fd671cbc89b
@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)
}
}
}
}
}
}
}
@dongfg
Copy link
Author

dongfg commented Sep 10, 2024

Gradle Wrapper 加速

gradle/wrapper/gradle-wrapper.properties
distributionUrl 从 bin 改成 all 可以同时下载 src

...
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-8.7-all.zip
...

无效时 Kill all Gradle Daemons

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment