前言
这个教程旨在教你使构建环境完全在镜像下运行,摆脱对代理的依赖。
更换Gradle下载地址
Gradle本体的下载地址位于项目文件夹\gradle\wrapper\gradle-wrapper.properties
中。
打开gradle-wrapper.properties
,你会看到类似以下的文本
1 2 3 4 5
| distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists
|
把services.gradle.org/distributions
换成mirrors.cloud.tencent.com/gradle
,也就是这样。
1 2 3 4 5
| distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-8.1.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists
|
注意:示例中的gradle-8.1.1-bin.zip
取决于你自己gradle-wrapper.properties
,没有把握请勿随便更改!
ROSA
下载地址 https://github.com/H2Sxxa/Rosa/releases/latest
镜像测试的报告 https://github.com/H2Sxxa/Rosa/blob/bin/forgegradle/class/TEST_REPORT.md
下载后配置好它的镜像修补就行,教程看Rosa首页的图片教程
(PS:觉得好用不妨给项目点个Star)
新版 Gradle
要改的地方一共有3个,这3个文件都在项目文件夹下
gradle.properties(如果没有可以直接新建一个gradle.properties然后添加保存)
将这一段直接加在最下面
1 2 3 4 5 6
| use_mirror = true
mirror_maven_url=download.mcbbs.net/maven
|
setting.gradle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| pluginManagement { repositories { if (use_mirror.toBoolean()) { removeIf { it instanceof MavenArtifactRepository && (it.url.toString() == "https://repo.maven.apache.org/maven2/") } maven { name 'Ali Mirror Maven' url "https://maven.aliyun.com/nexus/content/groups/public" allowInsecureProtocol = true } maven { name 'MC Mirror Maven' url "https://${mirror_maven_url}" allowInsecureProtocol = true } } gradlePluginPortal() mavenLocal() mavenCentral() } }
|
build.gradle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| repositories { if (project.use_mirror.toBoolean()) { removeIf { it instanceof MavenArtifactRepository && (it.url.toString() == "https://repo.maven.apache.org/maven2/") } maven { name 'Ali Mirror Maven' url "https://maven.aliyun.com/nexus/content/groups/public" allowInsecureProtocol = true } maven { name 'MC Mirror Maven' url "https://${mirror_maven_url}" allowInsecureProtocol = true } } mavenLocal() }
|
旧版 Gradle
要改的地方一共有2个,这2个文件都在项目文件夹下
gradle.properties(如果没有可以直接新建一个gradle.properties然后添加保存)
将这一段直接加在最下面
1 2 3 4 5 6
| use_mirror = true
mirror_maven_url=download.mcbbs.net/maven
|
build.gradle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| buildscript { repositories { if (use_mirror == "true") { removeIf { it instanceof MavenArtifactRepository && (it.url.toString() == "https://repo.maven.apache.org/maven2/") } maven { url "https://maven.aliyun.com/nexus/content/groups/public" } maven { url "https://${mirror_maven_url}" } } else { mavenCentral() maven { url "https://maven.minecraftforge.net" } } } }
repositories { if (use_mirror == "true") { removeIf { it instanceof MavenArtifactRepository && (it.url.toString() == "https://repo.maven.apache.org/maven2/") } maven { url "https://maven.aliyun.com/nexus/content/groups/public" } maven { url "https://${mirror_maven_url}" } } }
|