Skip to content

Instantly share code, notes, and snippets.

@jatin-lab49
Created June 22, 2020 20:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jatin-lab49/f9038b2340d82f36c5cc834415aa3730 to your computer and use it in GitHub Desktop.
Save jatin-lab49/f9038b2340d82f36c5cc834415aa3730 to your computer and use it in GitHub Desktop.
TIL-Lab49/Recovering from Gradle "Cannot lock Java compile cache"

Ran into a weird issue today where I was refactoring a lot of Java classes. Trying to run Gradle build via IntelliJ kept failing.

The error was:

> Task :compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Could not create service of type DefaultGeneralCompileCaches using GradleScopeCompileServices.createGeneralCompileCaches().

Running with --stacktrace showed this error:

Caused by: java.lang.IllegalStateException: Cannot lock Java compile cache (/projects/myproject/app/.gradle/5.5/javaCompile) as it has already been locked by this process.

I tried shutting down IntelliJ, but running gradle clean build via the command line gave the same error. Could not delete the /projects/myproject/app/.gradle/javaCompile folder too.

$ rm -rf javaCompile/
rm: cannot remove 'javaCompile/classAnalysis.bin': Text file busy
rm: cannot remove 'javaCompile/javaCompile.lock': Text file busy
rm: cannot remove 'javaCompile/taskHistory.bin': Text file busy

This was on an Ubuntu VM, so ended up killing all the gradle processes running (I had 3 running ps -ef | grep gradle , followed by kill ), and that finally solved the issue!

@goldsborough
Copy link

🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment