序言

gradle下载默认使用海外服务器,速度比较慢。可以修改 gradle/wrapper/gradle-wrapper.propertie文件。替换镜像地址。
腾讯云镜像
bash
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-9.4.1-bin.zip
阿里云镜像
bash
distributionUrl=https\://mirrors.aliyun.com/macports/distfiles/gradle/gradle-9.4.1-bin.zip
方案二
配置一次,电脑上所有项目都生效,不用每个项目都改一遍。
在Gradle用户目录下新建一个 init.gradle 文件。
Windows: C:\Users\你的用户名.gradle\init.gradle
Mac / Linux: ~/.gradle/init.gradle
将下面的内容复制进去并保存:
groovy
allprojects {
repositories {
// 移除默认的Maven Central和Google仓库
removeIf { it.url.toString().startsWith('https://repo.maven.apache.org') }
removeIf { it.url.toString().startsWith('https://dl.google.com') }
// 添加阿里云镜像
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
}
}