参考superbeyone的文章: Maven/Gradle配置国内镜像源
在 C:\Users\用户名\.gradle
文件夹下新建 init.gradle
文件并写入:
allprojects{
repositories {
def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/public'
def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter'
all { ArtifactRepository repo ->
if(repo instanceof MavenArtifactRepository){
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
remove repo
}
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
remove repo
}
}
}
maven {
url ALIYUN_REPOSITORY_URL
url ALIYUN_JCENTER_URL
}
}
}
如果只希望配置单一项目下的镜像源则打开项目根目录下的 build.gradle
更改 repositories
将 maven 块下的 url 改为相应的镜像仓库地址即可:
repositories {
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
mavenCentral()
}
镜像源采用阿里云仓库镜像: https://maven.aliyun.com/mvn/view