Configuring Gradle for Multi-Module Projects
Fast recall
Quick revision
Core answer
settings.gradle to declare all subprojects with include, a root build.gradle for shared configuration applied via allprojects {} or subprojects {}, and individual subproject build.gradle files for module-specific configuration. Modules reference each other as project dependencies.Whether you can structure a large codebase into cohesive modules with proper dependency relationships.
Using `subprojects {}` in the root build to apply plugins, which applies them to every module regardless of type — prefer convention plugins for explicit opt-in.
Mention composite builds for separating build logic from project builds, using convention plugins in `buildSrc/` to share configuration, and `./gradlew :module:task` syntax for targeted builds.
Interview-ready guide
Interview answer
A multi-module Gradle project uses settings.gradle to define the project structure and convention plugins to share configuration without the brittle subprojects {} pattern.
Project structure and discovery
settings.gradleincludes each subproject withinclude(':api', ':service', ':domain')— Gradle reads this file first and builds the project tree before any build logic runs- Subprojects reference each other with
dependencies { implementation project(':domain') }— Gradle builds a dependency graph from these references and compiles in the correct order automatically - Targeted execution:
./gradlew :service:testrebuilds only what that module needs — the domain module compiles if it is a dependency, unrelated modules are skipped
Convention plugins over `subprojects {}`
subprojects {}in the root build applies settings to every module blindly — a module that needs different behavior requires special-casing withif (project.name == ...), which becomes unmaintainable- Convention plugins in
buildSrc/are Kotlin or Groovy files that each module explicitly applies:apply plugin: 'com.example.java-conventions'— the module opts in to shared toolchain, test framework, and dependency management configuration - Different module types apply different convention plugins — an API module applies
java-library-conventions, a Spring Boot application appliesspring-boot-conventions; the conventions encode the team's standards once and modules consume them
When to start with convention plugins
- Start with convention plugins from day one, not
subprojects {}— migrating later requires touching every module's build file and is the most common source of inconsistency in multi-module Gradle projects - Use
dependencyResolutionManagementinsettings.gradlefor the version catalog — centralizing coordinates there makes them available to all modules without each module importing the catalog separately
Configuring Gradle for Multi-Module Projects
Direct Answer
A Gradle multi-module project uses settings.gradle to declare all subprojects with include, a root build.gradle for shared configuration applied via allprojects {} or subprojects {}, and individual subproject build.gradle files for module-specific configuration. Modules reference each other as project dependencies.
Common Mistakes & Pitfalls
Using subprojects {} in the root build to apply plugins, which applies them to every module regardless of type — prefer convention plugins for explicit opt-in.
Check your understanding
Answer these without looking back at the article.
- What is the difference between `subprojects {}`, `allprojects {}`, and convention plugins?
- How do you publish all modules of a multi-module Gradle project to Maven Central?
- What is a Gradle composite build and when would you use one?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.