忍不了,真的忍不了
发布时间:2025-06-24 20:24:33 作者:北方职教升学中心 阅读量:441
二、在这个文件中,你可以声明项目中包含哪些模块、各个仓库的列出顺序决定了 Gradle 在这些仓库中搜索各个项目依赖项的顺序。这些模块之间的依赖关系,以及全局的构建逻辑。各个仓库的列出顺序决定了 Gradle 在这些仓库中搜索各个项目依赖项的顺序。感兴趣的同学可自行百度gradle离线下载
对比gradle离线下载
,通过gradle国内镜像源
相对方便些,国内知名的gradle镜像源,包含阿里云和腾讯云
- 阿里云gradle镜像源:https://mirrors.aliyun.com/gradle
- 腾讯云gradle镜像源:https://mirrors.cloud.tencent.com/gradle/
可惜的是,阿里云gradle镜像源截至2019年就不再更新,gradle版本也停留在了gradle-5.6.2,若你使用的是gradle-5.6.2以上版本,更推荐你使用腾讯云gradle镜像源,使用方式如下:
替换https\://services.gradle.org/distributions
为https\://mirrors.cloud.tencent.com/gradle
distributionBase=GRADLE_USER_HOMEdistributionPath=wrapper/distsdistributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-8.2-bin.zipzipStoreBase=GRADLE_USER_HOMEzipStorePath=wrapper/dists
2. gradle依赖下载慢解决方案
为加速gradle依赖下载,我们可以通过国内镜像源加速,这里强烈安利 阿里云镜像源
源库 | 阿里云的镜像地址 |
---|---|
google() | https://maven.aliyun.com/repository/google |
mavenCentral() | https://maven.aliyun.com/repository/central |
gradlePluginPortal() | https://maven.aliyun.com/repository/gradle-plugin |
提示:上面仅列出我们使用到的镜像源,全量镜像源请见附录1:阿里云全量镜像源。
提示:若你使用的groovy,非kotlin,请转附录2:gradle依赖下载加速-groovy版
附录
附录1:阿里云全量镜像源
阿里云常见镜像库:https://developer.aliyun.com/mvn/guide
仓库名称 | 阿里云仓库地址 | 阿里云仓库地址(老版) | 源地址 |
---|---|---|---|
central | https://maven.aliyun.com/repository/central | https://maven.aliyun.com/nexus/content/repositories/central | https://repo1.maven.org/maven2/ |
jcenter | https://maven.aliyun.com/repository/public | https://maven.aliyun.com/nexus/content/repositories/jcenter | http://jcenter.bintray.com/ |
public | https://maven.aliyun.com/repository/public | https://maven.aliyun.com/nexus/content/groups/public | central仓和jcenter仓的聚合仓 |
https://maven.aliyun.com/repository/google | https://maven.aliyun.com/nexus/content/repositories/google | https://maven.google.com/ | |
gradle-plugin | https://maven.aliyun.com/repository/gradle-plugin | https://maven.aliyun.com/nexus/content/repositories/gradle-plugin | https://plugins.gradle.org/m2/ |
spring | https://maven.aliyun.com/repository/spring | https://maven.aliyun.com/nexus/content/repositories/spring | http://repo.spring.io/libs-milestone/ |
spring-plugin | https://maven.aliyun.com/repository/spring-plugin | https://maven.aliyun.com/nexus/content/repositories/spring-plugin | http://repo.spring.io/plugins-release/ |
grails-core | https://maven.aliyun.com/repository/grails-core | https://maven.aliyun.com/nexus/content/repositories/grails-core | https://repo.grails.org/grails/core |
apache snapshots | https://maven.aliyun.com/repository/apache-snapshots | https://maven.aliyun.com/nexus/content/repositories/apache-snapshots | https://repository.apache.org/snapshots/ |
提示:由于阿里云官网更新,大家查到的数据可能比上面少。例如,如果从仓库 A 和 B 均可获得某个依赖项,而您先列出了仓库 A,则 Gradle 会从仓库 A 下载该依赖项。例如,如果从仓库 A 和 B 均可获得某个依赖项,而您先列出了仓库 A,则 Gradle 会从仓库 A 下载该依赖项。
3. 查看
settings.gradle.kts
文件路径
根目录
- settings.gradle.kts文件是Kotlin DSL格式的settings文件,它用于配置项目的模块结构。
pluginManagement {repositories {// 使用阿里镜像源maven(url ="https://maven.aliyun.com/repository/google")maven(url ="https://maven.aliyun.com/repository/central")maven(url ="https://maven.aliyun.com/repository/gradle-plugin")google()mavenCentral()gradlePluginPortal()}}dependencyResolutionManagement {repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)repositories {// 使用阿里镜像源maven(url ="https://maven.aliyun.com/repository/google")maven(url ="https://maven.aliyun.com/repository/central")google()mavenCentral()}}rootProject.name ="Demo"include(":app")
建议:请不要随意改变仓库位置。忍不了,真的忍不了。
pluginManagement {repositories {// 使用阿里镜像源maven {url 'https://maven.aliyun.com/repository/google'}maven {url 'https://maven.aliyun.com/repository/central'}maven {url 'https://maven.aliyun.com/repository/gradle-plugin'}google()mavenCentral()gradlePluginPortal()}}dependencyResolutionManagement {repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)repositories {// 使用阿里镜像源maven {url 'https://maven.aliyun.com/repository/google'}maven {url 'https://maven.aliyun.com/repository/central'}google()mavenCentral()}}rootProject.name ="Demo"include ':app'
建议:请不要随意改变仓库位置。HTTP代理