Spring Boot multi module project with Gradle doesn't build
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Spring Boot multi-module Gradle builds commonly fail because plugin application, dependency scope, or project wiring is inconsistent across modules. Typical symptoms include missing main class detection, unresolved inter-module classes, duplicate boot jars, or tests failing due to incorrect task configuration. The fix is usually architectural rather than a single dependency tweak: keep one executable app module, treat shared modules as plain Java libraries, and centralize version management. This article provides a reliable baseline layout and a debugging sequence to resolve most multi-module build failures.
Recommended Project Structure
A stable setup typically has:
- Root build for shared config.
appmodule as the only Spring Boot executable.core,data, orapimodules as plain libraries.
settings.gradle:
Root build.gradle:
Apply Boot Plugin Only Where Needed
Only the runnable module should apply org.springframework.boot.
app/build.gradle:
Library modules should not produce boot jars:
core/build.gradle:
Applying Boot to all modules often causes conflicting packaging tasks.
Dependency and Task Diagnostics
Use Gradle diagnostics before making random edits.
If classes are unresolved, verify module dependency direction. app should depend on core, not the reverse (unless intentionally layered). Circular dependencies between modules can compile partially and fail at runtime or test phase.
If main class detection fails, set it explicitly:
Common Build Failures and Fixes
Could not find method implementation()in submodule: plugin mismatch (javanot applied).- Duplicate classes/resources: overlapping generated sources or improper shading.
- Tests failing due to missing context classes: module dependency scope wrong (
testImplementationvsimplementation). - Boot jar created for non-app module: disable boot tasks there.
Also verify Gradle and plugin versions are compatible with your Java runtime.
Practical Verification Workflow
A reliable way to avoid regressions is to validate the solution in three passes: baseline, controlled change, and repeatability check. First, capture a baseline outcome before you apply fixes. This could be a failing command, a wrong output sample, a stack trace, or a screenshot of current behavior. Second, apply one focused change and rerun exactly the same checks so you can attribute improvements to a specific edit. Third, rerun the checks multiple times or with slightly different inputs to ensure the fix is not accidental or data-specific.
A lightweight template you can adapt for most projects looks like this:
If your environment involves tests, add at least one focused regression test that would fail before the fix and pass after it. This turns a one-time troubleshooting success into a durable maintenance improvement, which is especially important when teams rotate ownership or upgrade dependencies later.
Common Pitfalls
- Applying
org.springframework.bootto every module instead of only the executable app module. - Mixing incompatible Gradle, Java, and Spring Boot versions.
- Declaring inter-module dependencies in the wrong direction and creating cycles.
- Ignoring
settings.gradleincludes, so modules exist on disk but not in build graph. - Debugging by trial-and-error without using
projects,dependencies, and task-specific logs.
Summary
Most Spring Boot multi-module Gradle build failures come from structure and plugin scope, not isolated dependency lines. Keep one boot-enabled app module, keep shared modules as libraries, and verify wiring with Gradle diagnostics. With clear module boundaries and consistent version management, builds become predictable and easier to evolve.
Related reading
- Spring Boot Multiple Datasource
- Spring boot multiple log files
- Spring Boot Multiple similar ConfigurationProperties with different Prefixes
- Spring Boot multiple SLF4J bindings
- Spring Boot not serving static content
- Spring Boot Primefaces - Unrecognized Content Type Exception
- Spring Boot MVC Multi-Module Executeable jar
- Spring Boot Oauth2 client credentials

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.