A Maven lifecycle is an ordered sequence of phases that define the steps needed to build and distribute a project. Running any phase automatically executes every preceding phase in that lifecycle, giving Maven a predictable, repeatable build process.
Key Points: • The default lifecycle covers the core build steps: validate, compile, test, package, verify, install, and deploy. • Each phase is bound to one or more plugin goals that do the actual work, such as the compiler plugin's compile goal running during the compile phase. • Running mvn package, for example, also runs validate, compile, and test first, since phases execute in order. • Maven has two other lifecycles besides default: clean, which removes build output, and site, which generates project documentation. • Because phases are standardized, any Maven project builds the same way regardless of team or codebase.
Example: Running mvn test on a project automatically triggers validate and compile first, ensuring the code is compiled before the test phase runs the unit tests.
Interview Tip: A concise interview answer is:
"Maven's lifecycle is an ordered list of phases like compile, test, package, and deploy, and running a phase runs everything before it in sequence. Plugins bind their goals to specific phases, so mvn package, for instance, compiles and tests the code before producing the jar."