// Copyright (C) 2024 Gradle, Inc.
//
// Licensed under the Creative Commons Attribution-Noncommercial-ShareAlike 4.0 International License.;
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

[[gradle_directories]]
= Gradle Directories

Gradle uses two main directories to perform and manage its work: the <<#gradle_user_home>> and the <<#project_root>>.

image::author-gradle-2.png[]

[[gradle_user_home]]
== Gradle User Home directory

By default, the Gradle User Home (`~/.gradle` or `C:\Users\<USERNAME>\.gradle`) stores global configuration properties, initialization scripts, caches, and log files.

It can be set with the environment variable `GRADLE_USER_HOME`.

TIP: Not to be confused with the `GRADLE_HOME`, the optional installation directory for Gradle.

It is roughly structured as follows:

[source,text]
----
├── 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
├── jdks    // <6>
│   ├── ⋮
│   └── jdk-14.0.2+12
├── wrapper
│   └── dists   // <7>
│       ├── ⋮
│       ├── gradle-4.8-bin
│       ├── gradle-4.9-all
│       └── gradle-4.9-bin
└── gradle.properties   // <8>
----
<1> Global cache directory (for everything that is 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.adoc#gradle_daemon, Gradle Daemon>>.
<5> Global <<init_scripts.adoc#init_scripts, initialization scripts>>.
<6> JDKs downloaded by the <<toolchains.adoc#sec:provisioning, toolchain support>>.
<7> Distributions downloaded by the <<gradle_wrapper.adoc#gradle_wrapper_reference,Gradle Wrapper>>.
<8> Global <<build_environment.adoc#sec:gradle_configuration_properties,Gradle configuration properties>>.

Consult the <<directory_layout.adoc#dir:gradle_user_home,Gradle Directories reference>> to learn more.

[[project_root]]
== Project Root directory

The project root directory contains all source files from your project.

It also contains files and directories Gradle generates, such as `.gradle` and `build`, as well as the Gradle configuration directory: `gradle`.

TIP: `gradle` and `.gradle` directories are different.

While `gradle` is usually checked into source control, `build` and `.gradle` directories contain the output of your builds, caches, and other transient files Gradle uses to support features like incremental builds.

The anatomy of a typical project root directory looks as follows:

[source,text]
----
├── .gradle // <1>
│   ├── 4.8 // <2>
│   ├── 4.9 // <2>
│   └── ⋮
├── build   // <3>
├── gradle
│   └── wrapper // <4>
├── gradle.properties   // <5>
├── gradlew // <6>
├── gradlew.bat // <6>
├── settings.gradle.kts // <7>
├── subproject-one  // <8>
|   └── build.gradle.kts    // <9>
├── subproject-two  // <8>
|   └── build.gradle.kts    // <9>
└── ⋮
----
<1> Project-specific cache directory generated by Gradle.
<2> Version-specific caches (e.g., to support incremental builds).
<3> The build directory of this project into which Gradle generates all build artifacts.
<4> Contains the JAR file and configuration of the <<gradle_wrapper.adoc#gradle_wrapper_reference,Gradle Wrapper>>.
<5> Project-specific <<build_environment.adoc#sec:gradle_configuration_properties,Gradle configuration properties>>.
<6> Scripts for executing builds using the <<gradle_wrapper.adoc#gradle_wrapper_reference,Gradle Wrapper>>.
<7> The project's <<settings_file_basics.adoc#sec:settings_file_script, settings file>> where the list of subprojects is defined.
<8> Usually, a project is organized into one or multiple subprojects.
<9> Each subproject has its own Gradle build script.

Consult the <<directory_layout.adoc#dir:project_root,Gradle Directories reference>> to learn more.

[.text-right]
**Next Step:** <<intro_multi_project_builds.adoc#intro_multi_project_builds,Learn how to structure Multi-Project Builds>> >>
