What is a Gradle project path, and how does it differ from a project name?
answer
- path = colon-separated, rooted at ':'
- name = last segment only
- name not globally unique, path is
- ':services:auth' vs name 'auth'
- logical path != physical dir
basics
~10 sA project path is a colon-separated identifier like ':services:auth' that uniquely locates a project in the build tree. The name is just the last segment ('auth'); the path encodes its full position.
solid answer
~40 sEvery project in a multi-project Gradle build has a **path** and a **name**. The path is a colon-separated string rooted at the build root — `:` is the root project, `:services` is a child, `:services:auth` is a grandchild. It uniquely identifies the project across the whole build. The **name** is only the final path segment (`auth`) and need not be unique on its own — two projects under different parents can both be named `auth` because their paths differ. You use the path everywhere you reference another project: `include(':services:auth')` in `settings.gradle.kts`, `project(':services:auth')` in dependencies, and `:services:auth:build` to invoke a task. The path is logical, not necessarily filesystem-based — by default it mirrors the directory layout, but you can override the physical directory with `projectDir`.
code
kotlin · 7 lines// settings.gradle.kts
rootProject.name = "platform"
include(":services:auth")
// In any build.gradle.kts you can inspect them:
// project.path -> ":services:auth"
// project.name -> "auth"go deeper
Know that ':services:auth' is a path, 'auth' is the name (last segment), and the path uniquely identifies a project.
Explain that names can repeat but paths cannot, and that paths are used for dependencies and task addressing.
Discuss the logical-vs-physical decoupling (projectDir remapping) and how paths drive task/dependency resolution.
Frame path conventions as part of a module naming/governance strategy in large monorepos, and the trade-offs of deep vs flat hierarchies.
## Path vs Name In a Gradle multi-project build, projects form a tree. Each node has two identifiers: - **Project path** — a colon-separated string describing the node's position in the tree, starting from the root. The root project's path is the single colon `:`. A direct child is `:services`; a child of that is `:services:auth`. The path is **globally unique** within the build. - **Project name** — the *last segment* of the path. For `:services:auth` the name is `auth`. Names are **not** required to be globally unique; `:services:auth` and `:platform:auth` can coexist because their full paths differ. ## Why two identifiers? Gradle needs an unambiguous handle to wire dependencies, resolve tasks, and address configuration. The path provides that. The name is a human-friendly short label and is what gets used (by default) for the published artifact's `archivesBaseName` and the project directory name. ## Where paths show up ```kotlin // settings.gradle.kts — declares the project into the tree include(":services:auth") // build.gradle.kts — a project dependency by path dependencies { implementation(project(":services:auth")) } ``` And on the command line, a task is addressed by the project path plus task name: `./gradlew :services:auth:test`. ## Path is logical, directory is physical By default the path `:services:auth` maps to the directory `services/auth` relative to the root. But the two are decoupled: in `settings.gradle.kts` you can remap `project(":services:auth").projectDir = file("modules/authentication")`. The path stays `:services:auth` regardless of where the files live. ## Accessing the root The leading colon means "from the root". `:auth` is a top-level project named `auth`; `auth` (no leading colon) in a task invocation is interpreted relative to the current project, which is rarely what you want in scripts — always qualify references with a leading colon for clarity.
- Can two projects in the same build share a name?Yes, as long as their full paths differ — e.g. ':services:auth' and ':platform:auth' both have name 'auth' but distinct, unique paths.
- What is the path of the root project?A single colon ':'. Its name is whatever rootProject.name is set to in settings.gradle.kts.
The path is like a file system absolute path (/services/auth) — unique and positional; the name is just the file name (auth), which can repeat in different folders.
saying these in an interview costs you the question
- Saying the project name must be unique across the whole build (only the path must be).
- Claiming the path always equals the directory path — it's logical and can be remapped with projectDir.