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


当前回答

只有手动删除缓存文件夹中的特定依赖才有效…由企业回购部门的同事制作的工艺品。

其他回答

有两种方法:

使用命令行选项刷新依赖项现金。 您可以删除本地缓存,其中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%工作,但是当另一个快照被释放并且它是依赖树的一部分时,您将再次面临刷新或清除缓存的选择。

你可以这样做

https://marschall.github.io/2017/04/17/disabling-gradle-cache.html

引用自禁用Gradle构建缓存

当你经常使用Gradle构建>个大型项目时,Gradle构建缓存可能是一个很棒的东西。然而,如果只是偶尔构建开源>项目,它很快就会变得很大。 要禁用Gradle构建缓存,请在~/.gradle/ Gradle .properties中添加以下代码行 org.gradle.caching = false 可以清除现有缓存 rm -rf $HOME/.gradle/caches/ rm -rf $HOME/.gradle/wrapper/

要刷新缓存的“释放”版本,唯一的选择是清除本地缓存。

rm -rf $HOME/.gradle/caches/

要刷新缓存的“快照”版本,可以:

./gradlew build --refresh-dependencies

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

gradlew clean cleaneclipse build eclipse --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将重新下载依赖项。