Changing buildDir in multi-project

So you can change the build directory for Gradle with the following:

./gradlew -PbuildDir=../someBuildDir

That works fine for a single project, but with multi-project builds it blows up in your face as multiple projects share the same build directory.

I’ve hacked around this problem currently by adding something like the following to each sub-project build.gradle

buildDir = mkdir "${buildDir}/rest-server"

So everything works fine this way, but I’m wondering if there’s a better way.

What are your actual requirements here? Do you need to be able to move the build directory to a location dynamically specified or is there something more granular that you’re needing to achieve?

Yeah I want to specify the build directory at build time dynamically. I call gradle from the cmake build system and want the gradle build directory to be inside the cmake build directory.