如何强制gradle重新下载依赖项?

当需要更新Gradle依赖项时,可以使用--refresh-dependencies命令行选项,这将忽略缓存并重新下载。此外,删除Gradle缓存目录下的相关文件也能达到相同效果。对于使用SNAPSHOT或动态版本的依赖,可以将其标记为'changing',Gradle会定期检查更新。在某些Gradle版本中,如2.14.1,修复了--refresh-dependencies的bug,确保能正确处理依赖刷新。
摘要由CSDN通过智能技术生成

本文翻译自:How can I force gradle to redownload dependencies?

如何告诉gradle从存储库重新下载依赖项?


#1楼

参考:https://stackoom.com/question/uute/如何强制gradle重新下载依赖项


#2楼

Generally, you can refresh dependencies in your cache with the command line option --refresh-dependencies . 通常,您可以使用命令行选项--refresh-dependencies刷新缓存中的依赖项 You can also delete the cached files under ~/.gradle/caches . 您还可以删除~/.gradle/caches下的缓存文件。 With the next build Gradle would attempt to download them again. 使用下一个版本,Gradle将尝试再次下载它们。

What is your specific use case? 你的具体用例是什么? Do you use dynamic dependency versions or SNAPSHOT versions? 您使用动态依赖版本还是SNAPSHOT版本?


On Unix systems, you can delete all the existing artifacts (artifacts and metadata) Gradle has downloaded using: 在Unix系统上,您可以删除Gradle使用以下命令下载的所有现有工件(工件和元数据):

rm -rf $HOME/.gradle/caches/

#3楼

You can tell Gradle to re-download some dependencies in the build script by flagging the dependency as 'changing'. 您可以通过将依赖关系标记为“更改”来告诉Gradle重新下载构建脚本中的某些依赖项。 Gradle will then check for updates every 24 hours, but this can be configured using the resolutionStrategy DSL. Gradle将每24小时检查一次更新,但可以使用resolutionStrategy DSL进行配置。 I find it useful to use this for for SNAPSHOT or NIGHTLY builds. 我发现将它用于SNAPSHOT或NIGHTLY构建很有用。

configurations.all {
    // Check for updates every build
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}

Expanded: 扩展:

dependencies {
    implementation group: "group", name: "projectA", version: "1.1-SNAPSHOT", changing: true
}

Condensed: 凝结:

implementation('group:projectA:1.1-SNAPSHOT') { changing = true }

I found this solution at this forum thread . 我在这个论坛帖子中找到了这个解决方案


#4楼

If you are using a recent version of Gradle, you can use --refresh-dependencies option. 如果您使用的是最新版本的Gradle,则可以使用--refresh-dependencies选项。

./gradlew build --refresh-dependencies

you can refer to the Gradle manual . 你可以参考Gradle手册

The --refresh-dependencies option tells Gradle to ignore all cached entries for resolved modules and artifacts. --refresh-dependencies选项告诉Gradle忽略已解析模块和工件的所有缓存条目。 A fresh resolve will be performed against all configured repositories, with dynamic versions recalculated, modules refreshed, and artifacts downloaded. 将对所有已配置的存储库执行全新解析,重新计算动态版本,刷新模块并下载工件。


#5楼

For Windows ...in order to make gradle re-download specific dependencies: 对于Windows ...为了使gradle重新下载特定的依赖项:

  1. delete the dependencies you want to re-download from the directory below: 从以下目录中删除要重新下载的依赖项:

     C:\\Users\\[username]\\.gradle\\caches\\modules-2\\files-2.1 
  2. delete all metadata directories at the path: 删除路径中的所有元数据目录:

     C:\\Users\\[username]\\.gradle\\caches\\modules-2\\metadata-* 
  3. run gradle build (or gradlew build if using gradle wrapper) in the project's root directory. 在项目的根目录中运行gradle build (或者如果使用gradle包装器,则使用gradlew build )。

note: the numbers in the file paths above might be different for you. 注意:上面文件路径中的数字可能与您有所不同。


#6楼

I think gradle 2.14.1 fixes the issue. 我认为gradle 2.14.1解决了这个问题。 The accepted answer is correct, but there is a bug in gradle with –refresh-dependencies. 接受的答案是正确的,但gradle中存在一个带有-refresh-dependencies的错误。 2.14.1 fixes that. 2.14.1解决了这个问题。

See https://discuss.gradle.org/t/refresh-dependencies-should-use-cachechangingmodulesfor-0s/556 请参阅https://discuss.gradle.org/t/refresh-dependencies-should-use-cachechangingmodulesfor-0s/556

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值