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


当前回答

对于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

其他回答

我太迟了,但是我的解决方案是单一的存储库。我认为删除~/。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拖拽文件。

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

如果你正在使用eclipse,如果你想强迫eclipse重新加载依赖项,你可以尝试下面的命令

gradlew clean cleaneclipse build eclipse --refresh-dependencies

删除所有缓存会重新下载所有依赖项。所以它需要很长时间,这是无聊的事情等待一次又一次重新下载所有的依赖。

我怎么能解决这个问题下面的方式。

只需删除需要刷新的组。

例如:如果我们想要刷新com.user.test组

rm -fr ~/.gradle/caches/modules-2/files-2.1/com.user.test/

然后从构建中删除依赖项。Gradle和重新添加它。 然后它将刷新我们想要的依赖项。

这对我很管用。 通过取消文件>设置>Gradle>离线工作按钮,确保Gradle没有被设置为离线。

将其添加到构建的顶层。Gradle,很高兴有上面的依赖

configurations.all {
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}

我确保我的依赖是这样写的:

implementation('com.github.juanmendez:ThatDependency:ThatBranch-SNAPSHOT') {
    changing = true
}

之后,我打开Android Studio中的Gradle面板,点击蓝色圆圈箭头按钮。我总是能看到我的更新得到一个新的新鲜副本。