Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

How does a Gradle multi-project build work: what does settings.gradle.kts do, and how does one subproject depend on another?

In a Gradle multi-project build, settings.gradle.kts in the root directory names the root project and lists the subprojects with include("app", "core"), which tells Gradle which directories are projects in this build. Each subproject has its own build script, and one depends on another with a project dependency such as implementation(project(":core")). Shared configuration belongs in convention plugins, and tasks can run for every project with gradle build or for one with gradle :app:test.

Why this question is asked

Most real Java applications are split into modules: a domain core, an API layer, an application that wires them together. Gradle handles this with a multi-project build, and understanding its few moving parts explains how Gradle finds projects, why a change in core rebuilds app, and how to run just the tests we care about. Interviewers ask this at the junior level because it is the foundation for everything else in larger builds. In this answer, we will look at the directory layout, see what the settings file does, connect two projects with a project dependency, share configuration properly, and run tasks across projects.

1The Layout of a Multi-Project Build

A multi-project build is one Gradle build that contains several projects. Each project is usually a directory with its own build.gradle.kts and its own source code. There is one root project at the top, and one settings.gradle.kts file next to it for the whole build.

Text
shop/
settings.gradle.kts # one per build: which projects exist
build.gradle.kts # root project, often nearly empty
gradle/libs.versions.toml # shared versions
build-logic/ # convention plugins (an included build)
core/
build.gradle.kts
src/main/java/...
app/
build.gradle.kts
src/main/java/...

Every project in this build shares one Gradle invocation: one daemon, one task graph and one dependency resolution context. That is what lets Gradle run tasks of several projects in parallel and know that app must wait for core.

2What settings.gradle.kts Does

Gradle runs a build in three phases. In the initialization phase, it looks for settings.gradle.kts and runs it to find out which projects take part. In the configuration phase it runs each project's build script, and in the execution phase it runs the requested tasks.

Java
// settings.gradle.kts
pluginManagement {
includeBuild("build-logic") // where our convention plugins come from
}
rootProject.name = "shop"
include("core", "app") // directories core/ and app/ are projects :core and :app
// ./gradlew projects
// Root project 'shop'
// +--- Project ':app'
// \--- Project ':core'
Step throughHow Gradle builds a multi-project build
  1. Initializationrun settings.gradle.kts: root name, include(...)
  2. Configurationrun each project's build.gradle.kts, create tasks
  3. Build the task graph:app:compileJava depends on :core:jar
  4. Executionrun tasks in order, independent ones in parallel

4 steps in order. Play them, or step through them one at a time.

Notice that include uses project paths, not file paths. :core is the core directory by default; a nested one such as include("services:billing") maps to services/billing and gets the path :services:billing. Without the settings file, or with a directory missing from include, Gradle simply does not treat that directory as a project, and its build script never runs. Setting rootProject.name explicitly matters too, because otherwise the root project takes the directory name, which differs between checkouts.

3One Subproject Depending on Another

A project dependency tells Gradle that one project uses another project's output, in the same way it would use a jar from Maven Central.

Java
// core/build.gradle.kts
plugins { id("myorg.java-library") } // applies java-library and our conventions
// app/build.gradle.kts
plugins { id("myorg.spring-service") }
dependencies {
implementation(project(":core")) // compile and run against core's classes
}
// ./gradlew :app:compileJava
// > Task :core:compileJava
// > Task :core:processResources
// > Task :core:classes
// > Task :core:jar
// > Task :app:compileJava

Notice that we never told Gradle to compile core first; the project dependency implies it. When app's compile classpath is resolved, Gradle sees it needs core's output, adds the tasks that produce it to the graph, and runs them first. The usual configuration rules apply: if core uses api for some of its dependencies, app sees them when compiling; if implementation, it does not. Some Gradle versions also offer type-safe project accessors, implementation(projects.core), after enabling a feature flag in settings; check your version.

4Sharing Configuration Without Copying It

Each project has its own build script, which keeps it understandable on its own. But core and app both need the same Java version, test settings and checks, and copying those blocks into every script means they will drift. The old answer was an allprojects or subprojects block in the root script that configures everyone from above.

The current recommendation is convention plugins: small plugins in the build-logic build, like myorg.java-library above, that hold the shared settings. Each project applies the ones it needs in its plugins block. This keeps every project's script honest about what it uses and lets Gradle configure each project independently, which works better with the configuration cache.

5Running Tasks Across Projects

From the root directory, a task name without a path runs that task in every project that has it, and a path runs it in one project only.

Shell
./gradlew build # build in every project: compile, test, jar, checks
./gradlew test # test in :core and :app
./gradlew :app:test # only app's tests (core is still compiled because app needs it)
./gradlew :core:build # only core
./gradlew :app:bootRun # a task that only app has
# From inside the app/ directory, ./gradlew test also runs only :app:test

Notice the difference between building a project and running its dependencies. :app:test does not run core's tests, but it does compile core, because app's test classpath needs core's classes. If we want core's tests too, we ask for them, or run build, which runs everything. With org.gradle.parallel=true in gradle.properties, Gradle runs independent projects' tasks at the same time.

6Follow-up questions

Where should a shared dependency version go?

In the version catalog, gradle/libs.versions.toml, so every project writes implementation(libs.jackson.databind) with the same version. For aligning whole families of libraries, also use a platform such as the Spring Boot BOM.

What does the root build.gradle.kts do in a modern build?

Often very little, sometimes nothing. It can declare plugins with apply false so that their versions are fixed once for all projects, but configuration itself lives in convention plugins and each project's own script.

What is buildDependents?

A task that builds a project and every project that depends on it, for example ./gradlew :core:buildDependents also builds app. It is useful after changing a shared module, to make sure nothing that uses it broke.

7Conclusion

In this answer, we saw that settings.gradle.kts defines a multi-project build: it names the root project and lists subprojects with include("app", "core") during the initialization phase. Each subproject has its own build script, one depends on another with implementation(project(":core")), and Gradle orders the tasks from those dependencies. Shared logic belongs in convention plugins rather than cross-project blocks, and tasks run for all projects with gradle build or for one with a path such as gradle :app:test.

What to say in the interviewAbout 80 seconds aloud

Open with

A multi-project build is one Gradle build with several projects, usually one directory each. The settings.gradle.kts file in the root is what defines it. In the initialization phase Gradle runs it to learn the root project name, which I always set explicitly with rootProject.name, and the list of subprojects from include, for example include app and core, which map to the app and core directories with paths colon app and colon core.

Then, if they want more

A directory that is not included is just a directory. Settings is also where I add pluginManagement with includeBuild build-logic for our convention plugins. Each subproject has its own build.gradle.kts. For app to use core, app declares implementation(project(":core")).

Gradle then knows that compiling app needs core's jar, so it adds core's compile and jar tasks to the graph and runs them first, and the usual api and implementation rules decide what app can see from core's dependencies.

For shared settings like the Java version and test configuration, I use convention plugins that each project applies, rather than a subprojects block in the root. To run things, ./gradlew build runs build in every project, while ./gradlew :app:test runs only app's tests, still compiling core because app needs it.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Gradle user manual
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How does a Gradle multi-project build work: what does settings.gradle.kts do, and how...": https://scrivio-interview-library.netlify.app/java/gradle/2712066885/