8

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?

6
  • Funny, I don't have this issue at all on ubuntu and the latest gradle version. Which gradle are you using?
    – frhd
    Aug 31, 2015 at 14:21
  • @frhd it's Gradle 2.0
    – superM
    Aug 31, 2015 at 14:23
  • 1. I always CTRL+C the build and there is no lock file. I'm not aware of a different way of cancelling a command line process :) 2. You can manually delete the .lock file. Of course, that leaves the question why you have the file in the first place.
    – frhd
    Aug 31, 2015 at 14:26
  • Can you delete the .lock file and try again running & cancelling the build? Maybe it was just a hiccup.
    – frhd
    Aug 31, 2015 at 14:27
  • The build isn't always successful after deleting the .lock file. Though when closing the terminal the issue resolves. But this still doesn't answer the question of terminating the build correctly.
    – superM
    Aug 31, 2015 at 14:49

2 Answers 2

11

Clear with a command:

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

MAC

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

LINUX

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

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.

4
  • 1
    Tried gradle -stop, but it's saying that no Gradle deamons are running.
    – superM
    Aug 31, 2015 at 15:08
  • 1
    1. Have you used gradle -stop with the same build file? 2. Was the build running at that time?
    – frhd
    Aug 31, 2015 at 23:35
  • The build was running, and I ran the command from the same directory in the second terminal.
    – superM
    Sep 1, 2015 at 6:33
  • 2
    find . -name ".lock" | xargs rm
    – Ajax
    Dec 2, 2018 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.