Skip to content

Instantly share code, notes, and snippets.

@aztack
Created April 2, 2020 09:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aztack/2edc92a8a3ed767cdd46f4a07a1b644e to your computer and use it in GitHub Desktop.
Save aztack/2edc92a8a3ed767cdd46f4a07a1b644e to your computer and use it in GitHub Desktop.
init.gradle
// ~/.gradle/init.gradle
allprojects {
def google_uri = new URI('https://maven.aliyun.com/repository/google')
def central_uri = new URI('https://maven.aliyun.com/repository/central')
def jcenter_uri = new URI('https://maven.aliyun.com/repository/jcenter')
repositories {
all {
ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://repo.maven.apache.org/maven2/') || url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by ${central_uri}."
repo.setUrl(central_uri)
} else if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by ${jcenter_uri}."
repo.setUrl(jcenter_uri)
} else if (url.startsWith('https://dl.google.com/dl/android/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by ${google_uri}."
repo.setUrl(google_uri)
}
}
}
}
buildscript {
repositories {
maven { url 'https://maven.aliyun.com/repository/public/' }
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://repo.maven.apache.org/maven2/') || url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by ${central_uri}."
repo.setUrl(central_uri)
} else if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by ${jcenter_uri}."
repo.setUrl(jcenter_uri)
} else if (url.startsWith('https://dl.google.com/dl/android/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by ${google_uri}."
repo.setUrl(google_uri)
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment