0

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).
TweeZz
  • 4,779
  • 5
  • 39
  • 53
  • Does this answer your question? [How to set gradle cache location?](https://stackoverflow.com/questions/28838699/how-to-set-gradle-cache-location) – amanin Jan 27 '23 at 17:51
  • No :) 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. – TweeZz Jan 27 '23 at 18:06
  • Tangential, but why would you want to do this? The whole point of project-specific `.gradle` files is that they're project-specific and in a standard location. – Dave Newton Jan 27 '23 at 18:17
  • Interesting ask. `.gradle` is a project-specific directory. I’m not sure if you can put it somewhere else, but that doesn’t make a lot of sense. – Abhijit Sarkar Jan 27 '23 at 18:18
  • I do not understand. You ask: `it will create a .gradle folder **in which a gradle distribution gets unzipped. Is there a way to change the location of that folder**`. Well, first answer of the linked question : `./gradlew -g $YOUR_CUSTOM_DIR anyTask` -> The wrapper is then put in that directory, not in .gradle. – amanin Jan 27 '23 at 18:35
  • -g is the same as setting GRADLE_USER_HOME. That's not what I'm looking for :) – TweeZz Jan 28 '23 at 09:37
  • I understand now. You want to change *project-specific cache location*. I do not know a way to change that, I am not sure it is possible. However, there is some things I do not understand. Why using `backend` directory as work directory ? Why not directly CI project directory ? The project specific cache means to store information for all modules of the project. Putting it in a specific module looks weird to me. I do not know Github actions very well, but if you look at Gitlab-CI official templates, they merge gradle global cache into project specific one, directly in `$CI_PROJECT_DIR`. – amanin Jan 28 '23 at 10:07

1 Answers1

0

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.

TweeZz
  • 4,779
  • 5
  • 39
  • 53