Gradle delete task failing with “unable to delete file”

限于喜欢 提交于 2019-12-11 08:38:57

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/17445188/gradle-delete-task-failing-with-unable-to-delete-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!