Gradle 5'Cannot lock buildSrc build lock as it has already been locked by this process.'

We have a gradle build which dynamically create several tasks of GradleBuild type to run with different client library versions to test its compatibility. That worked fine with Gradle4 but after moving to Gradle5 I’m getting Cannot lock buildSrc build lock as it has already been locked by this process. error after execution of first of this tasks. So directory is locked by first build and is not released. Could you please advice how this can be fixed? It is like this

task testAll {
    dependsOn  clientVersions.collect { "runTestsWithClient$it" }
    clientVersions.forEach { version ->
        task "runTestsWithClient$version"(type: GradleBuild) {
            buildFile = "build.gradle"
            tasks = ["testClient"]
            startParameter.projectProperties = [clientVersion: version]
        }
    }
}

This won’t fix the issue but on a point of style you shouldn’t declare a task within a task. This is better:

task testAll {
    dependsOn  clientVersions.collect { "runTestsWithClient$it" }
} 
clientVersions.forEach { version ->
    task "runTestsWithClient$version"(type: GradleBuild) {
        buildFile = "build.gradle"
        tasks = ["testClient"]
        startParameter.projectProperties = [clientVersion: version]
    }
}