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

其他回答

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

rm -rf $HOME/.gradle/caches/

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

./gradlew build --refresh-dependencies

就我而言,上述方法都没用,我所做的是:

在构建。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%工作,但是当另一个快照被释放并且它是依赖树的一部分时,您将再次面临刷新或清除缓存的选择。

对于那些想知道在哪里运行gradle命令的人:

Open Android Studio 点击终端(你会在Android Studio的基础上找到它) 命令工具将打开 输入命令gradlew build——refresh-dependencies

可以删除缓存jar的文件夹。

在我的例子中,在Mac上,库被缓存在路径:

/ /用户/ MY_NAME / .gradle /缓存模块2 - 2.1 / cached-library-to-remove /文件

我删除了缓存的库文件夹(在上面的例子中是“cache -library-to-remove”),删除了我的项目的构建文件夹,并重新编译。 然后下载了新库。