Multiple GradleBuild-typed tasks combined with parallel execution leads to concurrency errors in referred project

We have the following setup:

project A task1 of type GradleBuild, executing (project B task sometask) task2 of type GradleBuild, executing (project B task sometask)

project B task sometask

Now, if we execute a task on project A that depends on both task1 and task2, they are run concurrently, but then it seems they inadvertently call “sometask” concurrently on project B as well, leading to various concurrency errors there, some of the errors we have seen:

Gist of stacktrace

Thanks for the report, but I’m a little confused. When run with ‘–parallel’, I would not expect ‘task1’ and ‘task2’ to be executed in parallel (since they are part of the same project).

However, I can see how you’d get this happening if you have 2 different projects that have ‘GradleBuild’ tasks (’:projectA1:task1’, ‘:projectA2:task2’) that both execute the same task (’:projectB:sometask’).

The reason for the concurrency errors is that while it’s safe to run 2 different Gradle builds in the same project concurrently, the locking that we do is based on the executing process. With ‘GradleBuild’ tasks run in parallel, both ‘builds’ run in the same process, so this process-level locking doesn’t work.

I’ve raised GRADLE-3253 for this bug. Thanks for reporting. Unfortunately I can’t think of an easy fix or workaround at this time.

You’re right. It’s two different projects. Thanks for the reply and bug report.