Skip to content

Instantly share code, notes, and snippets.

@log2c
Last active November 24, 2021 07:33
Show Gist options
  • Save log2c/3468e5ce7ca96e9f611d284549269917 to your computer and use it in GitHub Desktop.
Save log2c/3468e5ce7ca96e9f611d284549269917 to your computer and use it in GitHub Desktop.
Gradle国内替换源加速(放在用户目录的.gradle目录下)二选一,代理 or 阿里云镜像
## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Wed Sep 01 08:32:56 CST 2021
systemProp.http.proxyHost=127.0.0.1
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=7890
systemProp.http.proxyPort=7890
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().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")
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment