The first time you trigger a gradle task using gradle wrapper, it will create a .gradle folder in which a gradle distribution gets unzipped. Is there a way to change the location of that .gradle folder?
Setting the GRADLE_USER_HOME environment variable is not what I'm looking for. When you set GRADLE_USER_HOME to for example /c/temp, then it will indeed be downloading some stuff in there (a cache folder and others). But that then still creates a ".gradle" directory in my project folder. I'm looking for a way to change that last directory.
Our project is structured as follows:
ROOT
│ ...
├── backend
│ ├── src
│ │ └──...
│ └── build.gradle
├── lib
│ ├── src
│ │ └──...
│ └── build.gradle
├── gradle
│ └── wrapper
├── gradlew
├── gradlew.bat
├── settings.gradle
The .gradle
folder which gets created the first time you run a gradle task is directly under the root folder. That's the one I'd like to control.
Why I want to do this?
In our pipelines (on github), we're using several templates which we do not have under our control. There's a template to build the code, one to run a sonar scan, etc..
Those templates also cache certain folders. And that's the place where we're currently getting a warning when the pipeline is trying to upload folders to be cached. I'm trying to get rid of that warning: WARNING: backend/.gradle: no matching files.
In our project, the .gradle folder is not being created in the backend folder, but in the root folder. If I have a way to configure where the .gradle folder is being created, the warning would be gone.
The templates are trying to cache the following 2 folders:
$GRADLE_USER_HOME/cache
(that is working as we are setting the GRADLE_USER_HOME env variable to the project directory)$CI_PROJECT_DIR/$CONF_WORK_DIRECTORY/.gradle
(this one causes the warning).
The answer is that you can not the project specific
.gradle
directory.I was however able to change the structure of the project to achieve what I needed. Now, I do not have any gradle files anymore in the root directory. Each gradle project in the repository has it's own
settings.gradle
,build.gradle
,gradlew.bat
,gradlew
files.In each sub folder, I now have a .gradle folder auto generated when running any gradle task on a sub project.