在 %userprofile%/.gradle 路径下,新建init.gradle文件,编辑写入:
def replacer = [
'http[s]://repo1.maven.org/maven2': 'https://maven.aliyun.com/repository/public',
'http[s]://jcenter.bintray.com': 'https://maven.aliyun.com/repository/public',
'http[s]://maven.google.com': 'https://maven.aliyun.com/repository/google',
'http[s]://plugins.gradle.org/m2': 'https://maven.aliyun.com/repository/gradle-plugin',
'http[s]://repo.spring.io/libs-milestone': 'https://maven.aliyun.com/repository/spring',
'http[s]://repo.spring.io/plugins-release': 'https://maven.aliyun.com/repository/spring-plugin',
'http[s]://repo.grails.org/grails/core': 'https://maven.aliyun.com/repository/grails-core',
'http[s]://repository.apache.org/snapshots': 'https://maven.aliyun.com/repository/apache-snapshots',
]
gradle.settingsEvaluated { settings ->
settings.buildCache {
local {
directory = new File('E:\\temp\\gradle')
removeUnusedEntriesAfterDays = 30
}
}
settings.pluginManagement {
repositories {
replacer[mavenCentral().url.toString().replaceAll('http[s]', 'http[s]')] = 'https://maven.aliyun.com/repository/public'
replacer[jcenter().url.toString().replaceAll('http[s]', 'http[s]')] = 'https://maven.aliyun.com/repository/public'
replacer[google().url.toString().replaceAll('http[s]', 'http[s]')] = 'https://maven.aliyun.com/repository/google'
gradlePluginPortal()
all { repo ->
if (repo instanceof MavenArtifactRepository) {
replacer.each { k, v ->
if (repo.url.toString().matches(k)) {
repo.url = v
}
}
}
}
}
}
}
allprojects {
repositories {
all { repo ->
if (repo instanceof MavenArtifactRepository) {
replacer.each { k, v ->
if (repo.url.toString().matches(k)) {
repo.url = v
}
}
}
}
}
}