Skip to content

Instantly share code, notes, and snippets.

@chisaato
Last active November 30, 2020 08:32
Show Gist options
  • Save chisaato/481044d83027368e2459a21cd3180924 to your computer and use it in GitHub Desktop.
Save chisaato/481044d83027368e2459a21cd3180924 to your computer and use it in GitHub Desktop.
init.gradle
def replaceRepository = {
def ALIYUN_MAVEN_REPOSITORY_URL = "https://maven.aliyun.com/repository/public"
def ALIYUN_JCENTER_URL = "https://maven.aliyun.com/repository/jcenter"
def ALIYUN_GOOGLE_URL = "https://maven.aliyun.com/repository/google"
def ALIYUN_GRADLE_PLUGIN_URL = "https://maven.aliyun.com/repository/gradle-plugin"
def ALIYUN_SPRING_URL = "https://maven.aliyun.com/repository/spring"
def ALIYUN_SPRING_PLUGIN_URL = "https://maven.aliyun.com/repository/spring-plugin"
def ALIYUN_GRAILS_CORE_URL = "https://maven.aliyun.com/repository/grails-core"
def ALIYUN_APACHE_SNAPSHOTS_URL = "https://maven.aliyun.com/repository/apache-snapshots"
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
// println url
// 改用contains判断
if (url.contains("repo.maven.apache.org/maven2")) {
println "仓库 ${repo.url} 已经替换为 ${ALIYUN_MAVEN_REPOSITORY_URL}"
remove repo
}
if (url.contains("jcenter.bintray.com")) {
println "仓库 ${repo.url} 已经替换为 ${ALIYUN_JCENTER_URL}"
remove repo
}
if (url.contains("maven.google.com")) {
println "仓库 ${repo.url} 已经替换为 ${ALIYUN_GOOGLE_URL}"
remove repo
}
if (url.contains("plugins.gradle.org/m2")) {
println "仓库 ${repo.url} 已经替换为 ${ALIYUN_GRADLE_PLUGIN_URL}"
remove repo
}
if (url.contains("repo.spring.io/libs-milestone")) {
println "仓库 ${repo.url} 已经替换为 ${ALIYUN_SPRING_URL}"
remove repo
}
if (url.contains("repo.spring.io/plugins-release")) {
println "仓库 ${repo.url} 已经替换为 ${ALIYUN_SPRING_PLUGIN_URL}"
remove repo
}
if (url.contains("repository.apache.org/snapshots/")) {
println "仓库 ${repo.url} 已经替换为 ${ALIYUN_APACHE_SNAPSHOTS_URL}"
remove repo
}
}
}
maven { url ALIYUN_MAVEN_REPOSITORY_URL }
maven { url ALIYUN_JCENTER_URL }
maven { url ALIYUN_GOOGLE_URL }
maven { url ALIYUN_GRADLE_PLUGIN_URL }
maven { url ALIYUN_SPRING_URL }
maven { url ALIYUN_SPRING_PLUGIN_URL }
maven { url ALIYUN_APACHE_SNAPSHOTS_URL }
println "添加maven本地仓库"
mavenLocal()
}
allprojects {
buildscript {
repositories replaceRepository
}
repositories replaceRepository
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment