Project buildDir setup at runtime

I have a gradle project and I’m automating it’s build process. However, I need to setup the buildDir (or override the buildDir in the build.gradle file) when I run gradle, so I can build in the automation platform’s custom directory.

Is there any way to set the buildDir at gradle runtime?
I tried, without success, the following:

gradle -DbuildDir=/custom build
gradle -PbuildDir=/custom build
gradle -Doutput.dir=/custom build
gradle -Poutput.dir=/custom build

Thanks for helping