Gradle删除任务因“无法删除文件”而失败 [英] Gradle delete task failing with "unable to delete file"

查看:725
本文介绍了Gradle删除任务因“无法删除文件”而失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 任务cleanExtra(类型:删除){
删除'../version.properties'
}

clean.dependsOn(cleanExtra)

有时,当我调用 gradle clean 时,它将失败,并显示Unable to delete file:(...)/ version.properties 。但是,如果我再次调用同一个清理任务,它将成功删除任务。



为什么会发生这种情况?无论如何避免它?

解决方案

听起来像JIRA问题 Gradle-2244


无法删除文件/目录,那么后续清理将会
成功。

从最后一条评论:


经过一番研究,看起来这可能是由于
Windows JDK(包括IBM)中的一个错误造成的。 Ant在
失败删除之后使用强制GC的策略,然后等待少量时间。鉴于这
似乎是Ant的一个成功策略,我们已采用它。


此问题被标记为固定在版本1.1-rc-1中。据推测,您观察到的行为是修复,这是JDK错误的解决方法。所以我会猜测这种行为可能发生在更高版本的Gradle中。


I have the following delete task added to my build.gradle file:

task cleanExtra(type: Delete) {
    delete '../version.properties'
}

clean.dependsOn(cleanExtra)

Sometimes, when I call gradle clean, it will fail with "Unable to delete file: (...)/version.properties". But if I call the same clean task a second time, it will successfully delete the task.

Why does this happen? Anyway to avoid it?

解决方案

It sounds like JIRA issue Gradle-2244 :

Unable to delete file/directory, and then a subsequent clean will succeed.

From the last comment:

After some research, it appears that this may be due to a bug in the Windows JDKs (incl IBM). Ant uses a strategy of forcing a GC after a failed delete and then waiting a small amount of time. Given that this appears to be a successful strategy for Ant, we have adopted it.

This issue is marked as fixed in version 1.1-rc-1. Presumably the behaviour you observe is "the fix", which a workaround for a JDK bug. So I'd guess that this behaviour may occur in later versions of Gradle.

这篇关于Gradle删除任务因“无法删除文件”而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆