Should the .gradle folder be added to version control?

Version ControlGradle

Version Control Problem Overview


Gradle creates a folder called .gradle. Should I track it with my version control (i.e. git)?

More importantly, why / why not?

Version Control Solutions


Solution 1 - Version Control

Should I track the .gradle directory?

No. It can safely be ignored.


Why should I ignore it?

It's purely for caching information, you don't want it in your repo because:

  • it can get big and be full of binary files
  • there can be machine specific data in there
  • there's a lot of churn in there (you'd be constantly committing changes to files in there)
  • everything in there can be completely re-generated whenever it is needed anyway

It's basically a temp directory that Gradle is dropping in the middle of your source code (why Gradle thinks that's an appropriate thing to do is a different question).

You can tell the "cache directory" nature of the directory by the name of the switch that lets you change where it goes: "--project-cache-dir".

Though I hate having binary files in my source tree, I usually just end up adding the directory to my ignore file because somewhere along the line I'll forget to use the switch from some command line or from my IDE or something and then end up having to deal with the directory anyway.


How do I ignore it?

Git users can add a line with just .gradle to the .gitgnore file and Git will ignore all files in any directory with that name.

Mercurial users will want to look up the .hgignore file.

For other version control systems, refer to the documentation - they all have a feature to support this.

Solution 2 - Version Control

The .gradle folder contains different calculated information about your gradle build (e.g. cached outputs/input information). You definitely shouldn't check that folder into your version control system.

Solution 3 - Version Control

You don't need to keep the .gradle folder.

Because once you execute gradle build command again, you can make almost the same .gradle folder again.

But when you use the gradle.setting file under .gradle you might need to move it to root folder of the project.

Solution 4 - Version Control

I was new to Gradle and thought that the .gradle folder will contain generic information such as dependency mappings, etc and uploaded it on version control. I then tried setting up a new machine with a different OS flavor and Java version using code from the version control including the .gradle folder and ran into errors. Turned out that the .gradle folder contains machine specific information and is used for caching on local. Do not include the .gradle folder in version control and try setting up a new machine with the code, the gradle daemon will do the rest.

Solution 5 - Version Control

when we start the gradle it create the .gradle folder inside your home directory. It consist of native (information about your system) and caches. Caches further consist of plugins and all other jars dependencies.

When we build the the project first time at that time it download dependencies and plugins and cheched them here. next time when we need them it, it get from here. even when we need them in eclipse to compile the code (=>gradle eclipse), its dependencies are added from cache

As it will keep updating and adding when you run gradle. so i guess we do not added it to version control.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionrocketscientistView Question on Stackoverflow
Solution 1 - Version ControlShornView Answer on Stackoverflow
Solution 2 - Version ControlRene GroeschkeView Answer on Stackoverflow
Solution 3 - Version ControlNagaView Answer on Stackoverflow
Solution 4 - Version ControlVarunView Answer on Stackoverflow
Solution 5 - Version ControlAKTView Answer on Stackoverflow