Run mvn spring-bootrun from parent module?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
In a multi module Maven project, running spring-boot:run from the parent module can fail if plugin configuration or module selection is unclear. Maven executes plugins in the current project context unless you direct it to a child module. The reliable solution is to target the application module explicitly.
Understand Parent and Child Roles
A parent pom usually has packaging type pom and no runnable application classes. Your Spring Boot app lives in one child module, often named app, web, or service.
From the repository root, run the plugin against that module using -pl and optionally -am to build required dependencies.
-pl appselects the application module.-amalso builds upstream modules required byapp.
This is the most common command for root level execution.
Configure Plugin in the Application Module
Keep spring-boot-maven-plugin in the runnable module, not only in the parent. Parent pluginManagement can define versions, but child modules still need plugin declaration to activate goals.
If the plugin is missing in child build plugins, goal resolution can fail even though parent versions are defined.
Profiles and Properties from Parent
Running from root often depends on parent profile defaults, JVM options, and shared properties. You can pass profile and application arguments directly through Maven.
This keeps environment setup reproducible for the team and CI tasks.
Troubleshooting Command Failures
If Maven cannot find the selected module, check modules in parent pom and confirm module directory names match -pl selector. You can also use group and artifact coordinates for clarity.
If Spring Boot reports no main class, verify that the app module contains a valid @SpringBootApplication entry point and that packaging settings are correct.
When startup uses stale classes, run mvn -pl app -am clean spring-boot:run to force recompilation.
Another useful option is running from inside the app module directory when debugging plugin behavior:
This bypasses reactor module selection issues and helps isolate whether root level command flags are the cause. Once stable, move back to parent level commands for consistent team workflows.
In CI, keep one scripted entry point for local and pipeline runs so developers do not maintain separate command variants. A Makefile or wrapper script around Maven commands can standardize options and reduce setup friction for new contributors. Teams can then update one command definition when build flags change, which lowers maintenance overhead and onboarding time.
Common Pitfalls
A common pitfall is running spring-boot:run on the parent pom module directly. Parent modules are aggregators and usually not executable.
Another issue is defining plugin versions only in parent pluginManagement and forgetting to declare the plugin in child modules.
Developers also skip -am, then wonder why dependent local modules are not built. Include it when app module depends on sibling modules.
Finally, mismatched Java version settings between parent and child can cause runtime startup errors. Keep toolchain properties centralized and consistent.
Summary
- Use
mvn -pl app -am spring-boot:runfrom the parent directory. - Declare Spring Boot plugin in the runnable child module.
- Use parent
pluginManagementfor versions, not goal activation. - Pass profiles and app arguments through Maven properties.
- Confirm module selection and main class setup when troubleshooting startup issues in shared repositories and CI environments consistently for teams daily use.
Related reading
- Run Spring-boot's main using IDE
- run spring batch job from the controller
- Runnable with a parameter?
- Running a MVC app using Spring Boot Hibernate MySql
- Running chron job on a single instance of spring service deployed on aws
- Running code after Spring Boot starts
- Running code after Spring Boot starts
- Running each Spring Scheduler in its own thread

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.