我如何告诉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.

其他回答

您需要重新下载它,因此您可以手动下载并替换损坏的文件,并再次同步您的项目。去这个位置 C: \用户【用户名】.gradle \包装\ dist gk2rcmfc6p2dg9u9ohc3hw9 55 \ gradle3.3-all \ \ gradle all.zip——3.3 在此删除gradle3.3allzip,并重新从该站点下载 https://services.gradle.org/distributions/ 找到相同的文件,下载并粘贴到该位置 然后同步你的项目。 希望它也适用于你。

我太迟了,但是我的解决方案是单一的存储库。我认为删除~/。Gradle /*是多余的。 我遇到的问题是,我正在删除目录的源代码和gradle正在获得另一个版本,而不是从nexus。 为了避免这种情况,我运行下一个:

~/.gradle$ find . -type d -name 'group.plugins.awssdk'
./caches/modules-2/files-2.1/group.plugins.awssdk
./caches/modules-2/metadata-2.23/descriptors/group.plugins.awssdk

~/.gradle$ rm -r ./caches/modules-2/files-2.1/group.plugins.awssdk   ./caches/modules-2/metadata-2.23/descriptors/group.plugins.awssdk

之后,gradle从nexus拖拽文件。

对于gradle 6.3版本,kotlin 1.3.70版本,Groovy 2.5.10版本,似乎更改更改为isChange

工作配置为

implementation("com.sample:commons:1.0.0-SNAPSHOT") {
        isChanging = true
    }

此外,运行此命令获取最新的

./gradlew assemble  --refresh-dependencies

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

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

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

通常,您可以使用命令行选项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.