Search code examples
gradledirectorydirectory-structure

What are each of the subfolders of the .gradle folder for?


I was quite surprised that I couldn't find this anywhere, but anyways, I would like to know the purpose of each folder in the .gradle folder, and how safe it is to delete them, especially in terms of portability.

  • I know that I need the caches folder, since it contains the downloaded dependencies.
  • The daemon folder seems to only contain logs?
  • workers is apparently empty for me
  • wrapper seems irrelevant, since I don't use gradle wrapper. Why does it even download all those wrappers?
  • No idea about native.

Solution

  • Directory layout is described in "The Directories and Files Gradle Uses" chapter of its user guide.

    ├── caches                   // <1>
    │   ├── 4.8                  // <2>
    │   ├── 4.9                  // <2>
    │   ├── ⋮
    │   ├── jars-3               // <3>
    │   └── modules-2            // <3>
    ├── daemon                   // <4>
    │   ├── ⋮
    │   ├── 4.8
    │   └── 4.9
    ├── init.d                   // <5>
    │   └── my-setup.gradle
    ├── wrapper
    │   └── dists                // <6>
    │       ├── ⋮
    │       ├── gradle-4.8-bin
    │       ├── gradle-4.9-all
    │       └── gradle-4.9-bin
    └── gradle.properties        // <7>
    
    1. Global cache directory (for everything that's not project-specific)
    2. Version-specific caches (e.g. to support incremental builds)
    3. Shared caches (e.g. for artifacts of dependencies)
    4. Registry and logs of the Gradle Daemon
    5. Global initialization scripts
    6. Distributions downloaded by the Gradle Wrapper
    7. Global Gradle configuration properties

    From version 4.10 onwards, Gradle automatically cleans its user home directory. The cleanup runs in the background when the Gradle daemon is stopped or shuts down. If using --no-daemon, it runs in the foreground after the build session with a visual progress indicator.

    The following cleanup strategies are applied periodically (at most every 24 hours):

    • Version-specific caches in caches/<gradle-version>/ are checked for whether they are still in use. If not, directories for release versions are deleted after 30 days of inactivity, snapshot versions after 7 days of inactivity.
    • Shared caches in caches/ (e.g. jars-*) are checked for whether they are still in use. If there's no Gradle version that still uses them, they are deleted.
    • Files in shared caches used by the current Gradle version in caches/ (e.g. jars-3 or modules-2) are checked for when they were last accessed. Depending on whether the file can be recreated locally or would have to be downloaded from a remote repository again, it will be deleted after 7 or 30 days of not being accessed, respectively.
    • Gradle distributions in wrapper/dists/ are checked for whether they are still in use, i.e. whether there's a corresponding version-specific cache directory. Unused distributions are deleted.

    native seem to contain platform-specific dependencies (like .so, .dll) for libraries like Jansi: it needs them to provide rich console output (like colours in the output). The code for that features is not documented, but you can take a look here. Particularly library.jansi.path system property points to ~/.gradle/native/jansi/1.17.1/linux64 (on my machine; you can check that by printing System.getProperties() in a custom Gradle task).

    workers seems to be used as a working directory for the workers described in Workers API.

    wrappers could be downloaded by the IDE. Basically, if you have this directory non-empty that means that you've actually used a wrapper at least once.