我如何告诉gradle从存储库中重新下载依赖项?
当前回答
对于Windows……为了让gradle重新下载特定的依赖项:
从下面的目录中删除要重新下载的依赖项: C:\Users\ %用户名% \模块2 \ \ .gradle \缓存文件- 2.1 删除该路径下的所有元数据目录: C:\Users\ %用户名% \模块2 \ \ .gradle \缓存元数据- * 在项目的根目录下运行gradle build(如果使用gradle wrapper,则运行gradlew build)。
注意:上述文件路径中的数字可能与您不同。
其他回答
有两种方法:
使用命令行选项刷新依赖项现金。 您可以删除本地缓存,其中artefast是由Gradle和触发构建缓存
使用——refresh-dependencies选项:
./gradlew build --refresh-dependencies
简单解释——refresh-dependencies选项告诉Gradle忽略已解析模块和工件的所有缓存条目。
长explanantion
WIth –refresh-dependencies’ Gradle will always hit the remote server to check for updated artifacts: however, Gradle will avoid downloading a file where the same file already exists in the cache. First Gradle will make a HEAD request and check if the server reports the file as unchanged since last time (if the ‘content-length’ and ‘last-modified’ are unchanged). In this case you’ll get the message: "Cached resource is up-to-date (lastModified: {})." Next Gradle will determine the remote checksum if possible (either from the HEAD request or by downloading a ‘.sha1’ file).. If this checksum matches another file already downloaded (from any repository), then Gradle will simply copy the file in the cache, rather than re-downloading. In this case you’ll get the message: "“Found locally available resource with matching checksum: [{}, {}]”.
使用删除: 当你删除缓存
rm -rf $HOME/.gradle/caches/
你只需要清理所有缓存的jar和sha1和,Gradle在你的机器上没有工件的情况下,必须下载所有东西。是的,第一次它将100%工作,但是当另一个快照被释放并且它是依赖树的一部分时,您将再次面临刷新或清除缓存的选择。
可以删除缓存jar的文件夹。
在我的例子中,在Mac上,库被缓存在路径:
/ /用户/ MY_NAME / .gradle /缓存模块2 - 2.1 / cached-library-to-remove /文件
我删除了缓存的库文件夹(在上面的例子中是“cache -library-to-remove”),删除了我的项目的构建文件夹,并重新编译。 然后下载了新库。
对于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
您可以删除特定组或工件id的缓存,而不是删除整个gradle缓存,就像这里的一些答案所建议的那样。我在我的.bash_profile中添加了以下函数:
deleteGradleCache() {
local id=$1
if [ -z "$id" ]; then
echo "Please provide an group or artifact id to delete"
return 1
fi
find ~/.gradle/caches/ -type d -name "$id" -prune -exec rm -rf "{}" \; -print
}
用法:
$ deleteGradleCache com.android.support
然后,在下一次构建或重新同步时,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.
推荐文章
- Gradle替代mvn安装
- 为什么要把Gradle Wrapper提交给VCS?
- 在构建中编写注释的语法是什么?gradle文件?
- 它目前正在被另一个Gradle实例使用
- 多个dex文件定义了landoid /support/v4/accessibilityservice/AccessibilityServiceInfoCompat
- Gradle:无法确定java版本从11.0.2开始
- Gradle构建脚本依赖项
- 如何确定Gradle的版本?
- Android Studio突然无法解析符号
- 没有找到Gradlew命令?
- 无法找到com.google.android.gms:play-services:3.1.59 3.2.25 4.0.30 4.1.32 4.2.40 4.2.42 4.3.23 4.4.52 5.0.77 5.0.89 5.2.08 6.1.11 6.1.71 6.5.87
- .dex文件中方法引用的数量不能超过64k API 17
- 我如何解决错误“minCompileSdk(31)指定在一个依赖的AAR元数据”在本机Java或Kotlin?
- Android工作室如何运行gradle同步手动?
- Android Studio在创建新项目时卡住了Gradle下载