gradle优先从mavenLocal加载依赖
最近开始使用gradle构建项目时,看见重复的依赖每次都要去下载,就查了下资料。
修改gradle文件,添加maven本地仓库
在build.gradle.kts中添加mavenLocal(), 如下
repositories {
// 添加maven本地仓库,优先从本地仓库寻找依赖
mavenLocal()
// 次优先级
maven ("https://maven.aliyun.com/nexus/content/groups/public" )
// 默认
mavenCentral()
}
maven本地仓库路径
官网:本地仓库路径从setting.xml文件中读取,优先从
USER_HOME(用户目录)/.m2/setting.xml中读取,其次从M2_HOME/conf/setting.xml中读取。如果这两处没找到文件,默认使用USER_HOME/.m2/repository作为本地仓库路径。
M2_HOME是maven的文件路径,用户在系统设置里定义的。
setting.xml中的本地仓库地址:
<localRepository>D:\maven-3.6.3\apache-maven-3.6.3\lib</localRepository>
原文:
Gradle uses the same logic as Maven to identify the location of your local Maven cache. If a local repository location is defined in a settings.xml, this location will be used. The settings.xml in USER_HOME/.m2 takes precedence over the settings.xml in M2_HOME/conf. If no settings.xml is available, Gradle uses the default location USER_HOME/.m2/repository.