'Gradle .lock files not removed when stopping build manually

When running gradle build from command line and manually terminating with Ctrl+Z, the .lock files, generated by gradle aren't removed. During the next build, I get a build failure with the following message:

.....
> Timeout waiting to lock artifact cache (...). It is currently in use by another Gradle instance.
Owner PID: ...
.....

When I kill the process and run build again, the message doesn't change. Even the process ID remains the same.

Is there a recommended way of stopping a gradle task from command line? Otherwise, is it possible to clean the hanging .lock files?



Solution 1:[1]

1. When running your non-daemon build in one terminal, you can stop it in another terminal simply with

gradle --stop

2. The .lock file should be cleaned up whenever a non-daemon build is terminated correctly within the same context. If not, you can delete it manually.

I recommend using the latest gradle version.

Solution 2:[2]

Clear with a command:

find . -name "*.lock" | xargs rm

MAC

find ~/.gradle/ -name "*.lock" | xargs rm

LINUX

find ~/.gradle/ -name "*.lock" | xargs rm

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 weston
Solution 2 Saket