Maven - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Maven Life Cycle

Maven Life Cycle

shape Introduction

The main concept of Maven is the build life cycle, which has a sequence of phases that define the order in which the goals have

shape Description

The Maven Life Cycle phase gives the order of goals and information about the packaging type in a project. The build Maven Life Cycle is divided into 3 types, they are: The above listed life cycles are independent of each other. Maven can execute more than one build life cycle at a time but the lifecycles should be executed in a sequence. At the same time, they should be defined as two separate commands in Maven. Build Maven Life Cycle is initially grouped into build phase sequence and later build phases are again divided into build goals. One can execute the entire build life cycle as “clean” or “site”, otherwise, the default life cycles-“install” or copy dependency of build goal gets executed. Remaining build phases have to be executed.

Default life cycle

shape Description

Default Maven Life Cycle is the general model in build process, which builds, tests and distributes the project. There are 21 phases in the default life cycle.

shape Conceptual figure

shape Phases

Phase Description
validate Validation of project is carried out and provides the necessary information required to complete the build process.
generate-resources Source code generation to include while compiling.
process-sources Source code is processed.
generate-resources Resource generation to include in packages.
process-resources Resources packing and copying into destination directory and is ready for package.
compile Source code compilation
process-classes Generated files into post-process after compilation.
generate-test-sources Test source generation to include in compilation.
process-test-sources Processing the test source code.
generate-test-resources Creation of resources to test.
process-test-resources Copying and processing the resources to test destination.
test-compile Compiling the test source code to test destination.
test With unit testing framework, one can run the tests.
prepare-package Preparing the package by performing operations before actual packaging.
package Gather the compiled code and package in JAR,WAR or EAR.
pre-integration test The actions to be performed before integration tests are executed like setting the environment.
integration test Processing and deploying the package.
post-integration test Performing the action after executing the integration tests like cleaning the environment.
verify Checking the packages are valid or not.
install Installing the package into local repository.
deploy Copying the package into remote repository.

Clean Life Cycle

shape Description

Clean Lifecycle is the simple life cycle in Maven that has 3 phases. All the three are invoked one by one when clean life cycle command mvn clean is executed. Clean is the important phase of Clean Lifecycle that has a goal clean:clean to delete the output of a build.

Site Life Cycle

shape Description

Site Life Cycle helps in project documentation and reporting process. There are four phases in this life cycle. All these will be invoked by running the command mvn site The default goals of site life cycle are:
  1. site:site
  2. site:deploy

Summary

shape Key Points

  • Build life cycle is divided into phases, which further are sub-divided into goals.
  • Validate, compile, test, package, install, and deploy are the important phases of the default build life cycle.
  • Clean and site are the simple life cycles used in Maven.