The Maven lifecycle defines a structured and standardized process to build, test, package, and deploy an application. In production environments, the Maven lifecycle ensures consistent, repeatable, and automated builds across teams and CI/CD pipelines.
Maven has three built-in lifecycles:
Used to clean previous build artifacts before starting a new build.
pre-clean
clean
post-clean
Deletes the target/ directory
Removes compiled classes and packaged artifacts
Ensures no old build artifacts interfere with new builds.
In CI pipelines, we always start with mvn clean to avoid inconsistent builds.
This is the most important lifecycle used in real projects.
It handles the entire build process from validation to deployment.
validate
Checks if the project structure is correct.
compile
Compiles source code.
test
Runs unit tests.
package
Creates artifact (JAR/WAR).
verify
Runs integration tests and quality checks.
install
Installs artifact into local Maven repository (~/.m2).
deploy
Deploys artifact to remote repository (Nexus/Artifactory).
Builds the application and creates JAR/WAR.
Builds and stores artifact locally.
Builds and pushes artifact to remote repository.
If you run:
Maven automatically runs:
validate → compile → test → package
It executes all previous phases in sequence.
Used to generate project documentation.
pre-site
site
post-site
site-deploy
Rarely used in CI pipelines but useful for documentation and reporting.
In real DevOps pipelines:
Developer pushes code
Jenkins/GitHub Actions triggers build
Maven runs:
If tests pass → artifact packaged
Artifact pushed to repository
CD pipeline deploys artifact
In enterprise environments:
Unit tests must pass in test phase
Code coverage tools run during verify
Sonar analysis integrates during verify phase
Artifact is immutable after package
Deploy phase is restricted to release pipelines only
We never allow developers to manually deploy using mvn deploy to production repositories.
Each phase can have plugins attached.
Example:
Surefire plugin → test phase
Jar plugin → package phase
Deploy plugin → deploy phase
Example:
Automatically binds to the test phase.
Because of standardized lifecycle:
Any developer machine
Any CI server
Any environment
Build behaves the same.
“Maven lifecycle defines structured build phases like validate, compile, test, package, install, and deploy. In production CI/CD, we typically run mvn clean verify to ensure clean builds and successful tests before packaging artifacts. Lifecycle ensures repeatable, standardized builds and supports plugin bindings for automation.”
Not a member yet? Register now
Are you a member? Login now