Concurrent Gradle runs intermittently fail

Gradle is still awesome: I have a large, multi-project build with several dozen applications and services. I’ve defined run targets using Gradle’s application plugin. This is great, because it lets developers use “gradle run” from an application’s directory to run just that application with all the correct arguments and system properties.

Some of these applications depend on services provided by others, so I need to be able to run several applications at once. I can open two terminal windows in two different sub-project directories and type “gradle run” in each window to run both applications simultaneously. Sometimes that works; other times, I get this error:

A problem occurred configuring project ':sw:java:apps:foo'.
> Could not open buildscript class cache for build file '/workspace/blah/sw/java/apps/foo/build.gradle' (/home/me/.gradle/caches/1.7-rc-1/scripts/build_onimlior3lcqq5bugng0kgjb4/ProjectScript/buildscript).
   > Timeout waiting to lock buildscript class cache for build file '/workspace/blah/sw/java/apps/foo/build.gradle' (/home/me/.gradle/caches/1.7-rc-1/scripts/build_onimlior3lcqq5bugng0kgjb4/ProjectScript/buildscript). It is currently in use by another Gradle instance.
     Owner PID: unknown
     Our PID: 3209
     Owner Operation: unknown
     Our operation:
      Lock file: /home/me/.gradle/caches/1.7-rc-1/scripts/build_onimlior3lcqq5bugng0kgjb4/ProjectScript/buildscript/cache.properties.lock

As far as I understand, this is a known limitation. I’ve created GRADLE-2835 in case it isn’t tracked yet.

Thanks.

I ran into the same problem today with Gradle 1.12. Is there a solution for this yet? After a few tries it solved itself with no changes to the buildscript or anything else.

The problem is more subtle than I originally thought. I think that the run task gets a read lock on the classes directory, and the JavaCompile task gets a write lock on it. So if you “gradle run” in one window, and leave that running while you change some source files, then do a Gradle build in another window, the second Gradle command will hang because it’s unable to acquire a write lock.

I imagine the implementation details are different from what I describe, but the behavior I see matches this description.