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


当前回答

以上的解决方案对我都不起作用。

如果你使用IntelliJ,解决这个问题的方法就是简单地刷新所有Gradle项目:

其他回答

如果您正在使用Intellij,您可以右键单击根项目,然后选择刷新gradle依赖项。

如果你使用的是最新版本的Gradle,你可以使用——refresh-dependencies选项。

./gradlew build --refresh-dependencies

你可以参考Gradle手册。

——refresh-dependencies选项告诉Gradle忽略已解析模块和工件的所有缓存条目。将对所有配置的存储库执行新的解析,重新计算动态版本,刷新模块,并下载工件。

通常,您可以使用命令行选项refresh-dependencies刷新缓存中的依赖项。你也可以删除~/.gradle/caches下的缓存文件。在下一次构建时,Gradle会再次尝试下载它们。

您的具体用例是什么?您使用动态依赖版本还是快照版本?


在Unix系统上,你可以删除Gradle已经下载的所有现有工件(工件和元数据):

rm -rf $HOME/.gradle/caches/

注意——refresh-dependencies不会总是重新下载每个工件;它将使用与存储库中存在的内容匹配的现有副本。从Gradle用户指南,刷新依赖:

The --refresh-dependencies option tells Gradle to ignore all cached entries for resolved modules and artifacts. A fresh resolve will be performed against all configured repositories, with dynamic versions recalculated, modules refreshed, and artifacts downloaded. However, where possible Gradle will check if the previously downloaded artifacts are valid before downloading again. This is done by comparing published SHA1 values in the repository with the SHA1 values for existing downloaded artifacts. [...] It’s a common misconception to think that using --refresh-dependencies will force download of dependencies. This is not the case: Gradle will only perform what is strictly required to refresh the dynamic dependencies. This may involve downloading new listing or metadata files, or even artifacts, but if nothing changed, the impact is minimal.

对于MAC

./gradlew build——刷新依赖项

对于Windows

Gradlew构建—刷新依赖项

也可以尝试gradlew assembleDevelopmentDebug—刷新依赖

对于Windows……为了让gradle重新下载特定的依赖项:

从下面的目录中删除要重新下载的依赖项: C:\Users\ %用户名% \模块2 \ \ .gradle \缓存文件- 2.1 删除该路径下的所有元数据目录: C:\Users\ %用户名% \模块2 \ \ .gradle \缓存元数据- * 在项目的根目录下运行gradle build(如果使用gradle wrapper,则运行gradlew build)。

注意:上述文件路径中的数字可能与您不同。