as 强制刷新 gradle 依赖缓存

本文介绍如何解决Gradle在开发过程中遇到的依赖缓存问题,提供了在Windows和Mac系统下强制Gradle重新拉取远程依赖数据的命令行指令,帮助开发者避免因本地缓存导致的版本更新不及时的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转自:https://blog.csdn.net/ziwang_/article/details/76383203

 

如果你正在开发一个库,并将它传上 jcenter 或者 jitpack,由于没上线,于是你一直上传 1.0 的版本,不停地覆盖远程仓库上的版本,但是你遗憾地发现本地的 gradle 出了问题,那么是由于 gradle 在下载依赖的同时自动将其缓存了一份在本地,所以等你第二次开启一个项目并依赖同一个库的同一个版本的时候,gradle 实际上只是拿了本地的缓存,但是这份小聪明,对于我前面所说的情况下的开发人员来说就是一个大麻烦,应当使用如下命令行命令来强制 gradle 拉去远程依赖数据 ——

Windows:    
gradlew build --refresh-dependencies 


Mac:
./gradlew build --refresh-dependencies  

请注意:--refresh 与 -dependencies 不应有空格存在,-dependencies 以参数形式依赖于 --refresh

参考资料: 
1.https://docs.gradle.org/current/userguide/dependency_management.html#sub:cache_refresh 
2.http://blog.csdn.net/cuiaamay/article/details/52797213
 

A problem occurred configuring root project 'hi'. > Could not resolve all files for configuration ':classpath'. > Could not resolve com.android.tools.build:gradle:7.4.2. Required by: project : > No matching variant of com.android.tools.build:gradle:7.4.2 was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.5' but: - Variant 'apiElements' capability com.android.tools.build:gradle:7.4.2 declares a library, packaged as a jar, and its dependencies declared externally: - Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 8 - Other compatible attribute: - Doesn't say anything about org.gradle.plugin.api-version (required '7.5') - Variant 'javadocElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a component, and its dependencies declared externally: - Incompatible because this component declares documentation and the consumer needed a library - Other compatible attributes: - Doesn't say anything about its target Java version (required compatibility with Java 8) - Doesn't say anything about its elements (required them packaged as a jar) - Doesn't say anything about org.gradle.plugin.api-version (required '7.5') - Variant 'runtimeElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a library, packaged as a jar, and its dependencies declared externally: - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8 - Other compatible attribute: - Doesn't say anything about org.gradle.plugin.api-version (required '7.5') - Variant 'sourcesElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a component, and its dependencies declared externally: - Incompatible because this component declares documentation and the consumer needed a library - Other compatible attributes: - Doesn't say anything about its target Java version (required compatibility with Java 8) - Doesn't say anything about its elements (required them packaged as a jar) - Doesn't say anything about org.gradle.plugin.api-version (required '7.5') * Try: > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. * Exception is: org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'hi'. at org.gradle.configuration.project.LifecycleProjectEvaluator.wrapException(LifecycleProjectEvaluator.java:84) at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:77) at org.gradle.configuration.project.LifecycleProjectEvaluator.access$400(LifecycleProjectEvaluator.java:55) at org.gradle.configuration.project.LifecycleProjectEvaluator$EvaluateProject.lambda$run$0(LifecycleProjectEvaluator.java:111) at org.gradle.api.internal.project.DefaultProjectStateR 怎么办
06-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值