Intellij gradle build vs. cmdline build

Over the years(especially with maven), I have seen tons of confusion when cmdline and IDE share the same output folders. For instance, intellij may be building while I then go and run ./gradlew testRelease which does a full clean and then test. At this point, one process is deleting files out from under the other one.

Sooooo, is there a way in gradle to detect it is being called from intellij and do something like

if(intellij)
buildDir = ‘intellij-output’
else
buildDir = ‘output’

thankfully, eclipse is still using it’s own output, so I do not have this issue.
thanks,
Dean