Maven's Three Lifecycles
Fast recall
Quick revision
Core answer
default for building and distributing a project, clean for removing prior build output, and site for project documentation. Each has an ordered set of phases. A lifecycle phase does work only through plugin goals bound to it by packaging defaults or project configuration.Understanding of Maven's lifecycle model beyond just the default lifecycle phases
Only knowing the default lifecycle and thinking 'clean' is just a phase, not a separate lifecycle
Explain that 'mvn clean package' invokes TWO lifecycles — clean first, then default up to package — showing you understand lifecycle independence
Interview-ready guide
Interview answer
Maven has default, clean, and site lifecycles. Default is the normal build and distribution path. Clean removes previous output, and site handles project documentation and reports. They are separate, which is why mvn clean package names two lifecycle targets.
The important detail is that phases themselves are ordering points. Actual work comes from plugin goals bound by the project's packaging and configuration. A phase does not guarantee some task ran unless the relevant goal is bound.
Maven's Three Lifecycles
Direct Answer
Maven defines three built-in lifecycles: default for building and distributing a project, clean for removing prior build output, and site for project documentation. Each has an ordered set of phases. A lifecycle phase does work only through plugin goals bound to it by packaging defaults or project configuration.
Code Example
# Run only the clean lifecycle through its clean phase
mvn clean
# Run the default lifecycle through package; does not clean first
mvn package
# Run clean, then the default lifecycle through verify
mvn clean verify
# Run the site lifecycle through site
mvn site
Each requested phase also causes earlier phases in that same lifecycle to run. The work at those phases depends on bound plugin goals.
Common Mistakes & Pitfalls
- Thinking clean is just a phase: Many freshers believe 'clean' is just another phase in the default lifecycle like compile or test, when it's actually a completely separate lifecycle with its own phases. This causes confusion about why 'mvn package' doesn't automatically clean first.
- Running clean every single time: Some developers get into the habit of always running 'mvn clean package' even for quick iterative development, which wastes time because clean deletes everything and forces a full rebuild from scratch. During active development, just run 'mvn package' unless you're troubleshooting strange issues.
- Ignoring the site lifecycle: Freshers often don't know the site lifecycle exists at all, missing an opportunity to generate useful project documentation and reports automatically from your codebase and Maven configuration.
Check your understanding
Answer these without looking back at the article.
- What are the phases of Maven's default lifecycle?
- When would you use mvn clean vs not?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.