Quick revision
The short answer
I would use a composite build when the pieces are separate builds with their own lifecycles, typically a library in one repository and a service that consumes it in another: includeBuild lets Gradle substitute the library's published dependency with the local build, so we can change both and test them together without publishing. Composite builds also keep each build's settings separate, and they are the usual way to host build logic as an included build-logic instead of buildSrc. Modules that are always versioned and released together belong in one multi-project build.
What to remember
In this answer, we saw that a multi-project build is one build with shared settings for modules released together, while a composite build combines complete builds that keep their own settings. includeBuild substitutes a published dependency with a local build by matching group and name, which lets us develop a library and its consumer together across repositories. Build logic is often hosted as an included build-logic instead of buildSrc, and the main deciding question is whether the pieces share a release lifecycle.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would use a composite build when the pieces are separate builds with their own lifecycles, typically a library in one repository and a service that consumes it in another: includeBuild lets Gradle substitute the library's published dependency with the local build, so we can change both and test them together without publishing. Composite builds also keep each build's settings separate, and they are the usual way to host build logic as an included build-logic instead of buildSrc. Modules that are always versioned and released together belong in one multi-project build.
Why this question is asked
Sooner or later every team hits the same friction: a bug fix needs a change in a shared library and in the service that uses it. The slow way is to change the library, publish a snapshot, bump the version in the service, and repeat for every iteration. Composite builds remove that loop. Interviewers ask when to use them because the answer shows whether we understand the line between one build and several builds, and why build logic is often hosted in an included build. In this answer, we will recap what each structure is, see how dependency substitution works, use it for a library and a consumer, look at build-logic as an included build, and finish with a way to decide.
1A Quick Recap of the Two Structures
A multi-project build is one build: one settings.gradle.kts includes several projects, they share one task graph and one set of build settings, and they usually live in one repository and are released together with the same version. Projects depend on each other with project(":core").
A composite build is a build that includes other complete builds. Each included build keeps its own settings file, its own projects and often its own repository. They are combined only for the duration of an invocation, and they connect through normal dependency coordinates, such as com.myorg:payments-client:4.1.0, rather than project paths.
2How Dependency Substitution Works
When a build includes another with includeBuild, Gradle looks at the group and name that each included project would publish. If the main build has a dependency on the same group and name, Gradle replaces the binary dependency from the repository with the included project's output, built from source, whatever version was requested.
7 messages in order. Play them, or step through them one at a time.
The repository version is never downloaded while the build is included.
Notice that nothing in the service's build.gradle.kts changes. It still declares the published coordinates. The substitution happens because of the includeBuild, and only while it is there, which is why many teams pass it on the command line rather than committing it.
3Working on a Library and Its Consumer Together
Here is the everyday use. The payments-client library and orders-service live in separate repositories checked out side by side.
Notice the benefit: we edit the library, run the service's tests, and see the effect in one command, with no snapshot publishing. IDEs understand composite builds too, so IntelliJ IDEA shows both builds and lets us navigate from the service into the library's source. When we are done, we release the library normally and remove the include.
Because each build keeps its own settings, the library still builds exactly as it does alone, with its own plugins and versions. That is the key difference from adding the library's directory as a subproject, which would mix two builds' settings and force them onto one structure.
4Build Logic as an Included Build
The second common use has nothing to do with libraries. Convention plugins for a build need to be compiled before the build scripts that apply them. Gradle's traditional place for that is the buildSrc directory, which is built automatically and put on the classpath of every build script.
The modern alternative is an ordinary included build called build-logic, included through pluginManagement { includeBuild("build-logic") }. It behaves like any other build, so it can be split into several plugin projects, tested and later moved to its own repository. buildSrc has the drawback that it is on the classpath of every script, so any change there invalidates the configuration of the whole build; with build-logic split into smaller plugin projects, a change only affects the projects that apply the changed plugin, and the structure is the same one we would use to publish the plugins later.
5Choosing Between Them
The deciding question is whether the pieces share a release lifecycle. If they are always versioned and released together, and a change usually spans them, they belong in one multi-project build, which gives the simplest dependency model and one place for settings. If they have separate versions, separate owners or separate repositories, keep them as separate builds and combine them with includeBuild when needed.
| Situation | Better fit | Why |
|---|---|---|
| Modules released together, one version | Multi-project build | One settings file, project(":x") dependencies |
| Library and consumer in separate repos | Composite build | Substitutes the published jar with local source |
| Testing a fix in an open source dependency | Composite build | Include its checkout temporarily |
| Convention plugins for this build | Included build-logic | Behaves like a normal build, can be split |
| Several apps sharing many always-changing modules | Multi-project, or reconsider repo split | Frequent cross-changes favour one build |
6Follow-up questions
Does includeBuild work when the versions do not match?
Yes. Substitution matches on group and name, not version, so the service gets the local build even if it declares 4.1.0 and the library is at 4.2.0-SNAPSHOT. That is usually what we want while developing, but it means we must remember to remove the include before trusting the build as a release.
Can a composite build replace a monorepo?
Partly. It lets separate repositories be developed together on one machine, but each still has its own CI, versions and releases. If teams constantly change several repositories at once, that is a sign the boundaries are wrong, and a multi-project build in one repository may be simpler.
What if the included build's coordinates do not match?
Gradle cannot substitute automatically, for example if the included project's group differs from the published one. We can declare the substitution explicitly in includeBuild with dependencySubstitution { substitute(module("com.myorg:payments-client")).using(project(":")) }.
7Conclusion
In this answer, we saw that a multi-project build is one build with shared settings for modules released together, while a composite build combines complete builds that keep their own settings. includeBuild substitutes a published dependency with a local build by matching group and name, which lets us develop a library and its consumer together across repositories. Build logic is often hosted as an included build-logic instead of buildSrc, and the main deciding question is whether the pieces share a release lifecycle.
Open with
I use a composite build when the pieces are separate builds with their own lifecycles, and a multi-project build when they are modules that are always versioned and released together.
Then, if they want more
The classic composite case is a library in one repository and a service in another. With includeBuild, either in settings or with --include-build on the command line, Gradle sees that the included build produces com.myorg:payments-client, matches it by group and name against the service's dependency, and substitutes the published jar with the local build.
So I can change the library, run the service's tests in one command, without publishing snapshots, and the IDE shows both. Each build keeps its own settings and plugins, so the library still builds exactly as it does alone, which is the difference from just adding it as a subproject.
The other common use is build logic: instead of buildSrc, many builds host convention plugins in an included build called build-logic through pluginManagement includeBuild. It behaves like a normal build, can be split into several plugin projects so a change does not invalidate everything, and can later be published.
If modules share one version, one release and change together most of the time, I keep them in one multi-project build with project dependencies, because that is simpler.
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 "When would you use a Gradle composite build (includeBuild) instead of adding projects to...": https://scrivio-interview-library.netlify.app/java/gradle/3baa7ab279/