When compiling a groovy project, gradle creates files in $projectRoot/build/
. Is there a way to configure this to e.g. an absolute path?
Asked
Active
Viewed 5.2k times
19

Henrik Andersson
- 45,354
- 16
- 98
- 92

Armand
- 23,463
- 20
- 90
- 119
3 Answers
37
Yes, there is. You can put the following line in your build script:
buildDir = 'your_directory'
Or in gradle.properties
file (no quotes around your_directory
in that case).
Build directory is a project property. You can view all project properties available to you by typing:
gradle properties

Sergey Weiss
- 5,944
- 8
- 31
- 40
-
Windows absolute path like `buildDir = 'R:\\buildMaria'` worked in `build.gradle` but failed in `gradle.properties` See also http://stackoverflow.com/questions/29116000/gradle-make-use-of-ramdisk – Paul Verest Mar 18 '15 at 07:42
-
3can it be done with some env variable? i need it to configure CI for the project – 4ntoine Dec 21 '17 at 12:16
-
So,t he key for `gradle.properties` is `project.buildDir=new/directory/location`? – FilBot3 Jan 15 '20 at 21:03
6
You can set project.buildDir
in your build.gradle
, or buildDir = PATH
in gradle.properties
.
And from environment variable like this:
export GRADLE_OPTS=-Dorg.gradle.project.buildDir=/tmp/gradle-build
See Build Environment section of the documentation here: https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_environment_variables
And Writing Build Scripts here (for buildDir property): https://docs.gradle.org/current/userguide/writing_build_scripts.html
(Current version of gradle when writing this: 4.5)

Dalibor Filus
- 1,140
- 9
- 19
2
You can add project.buildDir = 'your/directory' to the file build.gradle you can place it anywhere in separate line

tarn
- 546
- 6
- 10