Build Lifecycle Management

About

Build Lifecycle Management Plugins control the different phases of the Maven build lifecycle—such as compilation, testing, packaging, deployment, and installation. These plugins ensure that Maven can consistently build, test, and distribute projects by handling specific tasks at different lifecycle stages.

Maven defines three default lifecycles:

  1. Clean – Removes previous build artifacts.

  2. Default – Handles compilation, testing, packaging, and deployment.

  3. Site – Generates project documentation.

Each lifecycle consists of phases, and various plugins execute specific goals within these phases.

How Plugins Fit into the Maven Build Lifecycle?

Each plugin executes specific goals, and these goals are bound to phases in the Maven build lifecycle.

For example:

  • compile → maven-compiler-plugin (compile)

  • test → maven-surefire-plugin (test)

  • package → maven-jar-plugin (jar)

  • verify → maven-failsafe-plugin (integration-test)

  • install → maven-install-plugin (install)

  • deploy → maven-deploy-plugin (deploy)

1. Compilation & Code Processing Plugins

maven-compiler-plugin

The maven-compiler-plugin is responsible for compiling Java source files. It ensures that your project's source code is compiled using the correct Java version and compiler settings.

Syntax

This configuration compiles Java code using Java 17.

Configuration Options

Configuration
Description
Default

source

Specifies the Java source version

1.6

target

Specifies the Java target bytecode version

1.6

compilerArgs

Additional compiler arguments

None

debug

Enables debug symbols

true

failOnError

Stops the build if compilation fails

true

verbose

Prints detailed compiler output

false

skip

Skips compilation phase

None

Compiler Arguments -Xlint:unchecked

enable warnings for unchecked operations.

None

Compiler Arguments -Xlint:deprecation

enable warnings for deprecated operations.

None

maven-resources-plugin

The maven-resources-plugin is responsible for copying project resources (such as .properties, .xml, and .json files) into the appropriate build directories.

Syntax

This plugin executes in the process-resources phase to copy files from src/main/resources to target/classes.

Configuration Options

Configuration
Description
Default

resources

Specifies the directories for resource files

src/main/resources

includes

Specifies which files to include

**/*

excludes

Specifies which files to exclude

None

filtering

Allows variables in resources (${} placeholders)

false

maven-enforcer-plugin

The maven-enforcer-plugin ensures that projects adhere to rules, such as enforcing Java versions, dependency versions, and best practices.

Syntax

Configuration Options

Rule
Description

requireJavaVersion

Ensures a minimum Java version

requireMavenVersion

Ensures a minimum Maven version

requireOS

Restricts build execution to specific OS

bannedDependencies

Blocks unwanted dependencies

bannedPlugins

Blocks unwanted plugins

2. Testing Plugins

maven-surefire-plugin

The maven-surefire-plugin runs unit tests during the test phase of the Maven lifecycle. It executes JUnit, TestNG, and other testing frameworks.

Syntax

By default, it runs tests from src/test/java.

Configuration Options

Configuration
Description
Default

includes

Specify which test classes to run

**/Test*.java

excludes

Specify which tests to exclude

None

test

Runs a specific test class

None

forkCount

Number of JVMs to run tests in parallel

1

parallel

Enables parallel execution (methods, classes, both)

None

skipTests

Skips all tests

false

failIfNoTests

Fails the build if no tests are found

true

maven-failsafe-plugin

The maven-failsafe-plugin is designed for integration tests (ITs) and runs tests after the application is built and deployed.

Syntax

Failsafe ensures that even if an integration test fails, Maven doesn't stop the build immediately but allows post-build cleanup.

Configuration Options

Configuration
Description
Default

includes

Specify test classes to run

**/IT*.java

excludes

Specify test classes to exclude

None

errorFailingTests

Set to false to allow failures without stopping the build

true

skipITs

Skip integration tests

false

parallel

Run tests in parallel

None

maven-verifier-plugin

The maven-verifier-plugin is useful for functional testing of Maven projects. It verifies that the output of a Maven build meets the expected criteria.

Syntax

3. Packaging Plugins

maven-jar-plugin

The maven-jar-plugin is used to package Java applications into a JAR (Java ARchive) file. It includes compiled .class files, META-INF, and resource files.

Syntax

Configuration Options

Configuration
Description
Default

finalName

Name of the generated JAR file

project.artifactId-version.jar

classifier

Adds a suffix (e.g., -sources)

None

excludes

Files to exclude

None

includes

Files to include

None

maven-war-plugin

The maven-war-plugin is used to package web applications into a WAR (Web Application Archive) for deployment on Java web servers.

Syntax

Configuration Options

Configuration
Description
Default

failOnMissingWebXml

Whether to fail if web.xml is missing

true

warName

Name of the WAR file

project.artifactId-version.war

outputDirectory

Where to place the WAR file

target/

maven-ear-plugin

The maven-ear-plugin is used to create EAR (Enterprise Archive) files, which bundle multiple Java EE components (JARs and WARs).

Syntax

Configuration Options

Configuration
Description
Default

defaultJavaBundleDir

Directory for JAR modules

lib/

failOnMissingApplicationXml

Fail if application.xml is missing

true

generateApplicationXml

Generate application.xml automatically

true

maven-assembly-plugin

The maven-assembly-plugin allows custom packaging formats such as ZIP, TAR, TAR.GZ, and self-contained archives.

Syntax

Configuration Options

Configuration
Description
Default

descriptorRef

Predefined package types (jar-with-dependencies, etc.)

None

finalName

Name of the output archive

project.artifactId-version

formats

Output formats (zip, tar.gz, etc.)

zip

maven-shade-plugin

The maven-shade-plugin is used to create a fat JAR (Uber JAR) that includes all dependencies.

Syntax

Configuration Options

Configuration
Description
Default

finalName

Name of the output JAR

project.artifactId-version.jar

shadedArtifactAttached

Attach shaded JAR to build

false

4. Deployment & Installation Plugins

maven-install-plugin

The maven-install-plugin is used to install project artifacts (JAR, WAR, EAR, etc.) into the local repository (~/.m2/repository). This allows other projects on the same system to reference them.

Syntax

Configuration Options

Configuration
Description
Default

skip

Skip the installation step

false

repositoryLayout

Define repository structure

default

maven-deploy-plugin

The maven-deploy-plugin is used to deploy project artifacts to a remote repository (e.g., Nexus, Artifactory, or Maven Central) for sharing across teams or organizations.

Syntax

Configuration Options

Configuration
Description
Default

url

The repository URL for deployment

None (Must be provided)

repositoryId

The ID of the target repository

None

altDeploymentRepository

Alternative repository specification

None

wagon-maven-plugin

The wagon-maven-plugin is a Maven plugin provided by the Codehaus Mojo project that enables automated file transfers as part of a Maven build lifecycle. It leverages the Maven Wagon transport framework to upload or download files using various protocols such as SCP, FTP, HTTP, and more.

This plugin is ideal for:

  • Deploying build artifacts to non-Maven servers or directories

  • Automating backup, distribution, or deployment steps

  • Transferring files as part of custom CI/CD pipeline

Features

  • Supports standard Maven Wagon protocols (e.g., scp, ftp, http, file)

  • Can be bound to any Maven phase (like deploy or install)

  • Simple integration using server credentials from settings.xml

  • Fine-grained control over what files are transferred (via includes, excludes, fromDir, etc.)

Syntax

Configuration Options

Configuration
Description
Default

url

Remote location URL

Required

fromFile

Local file to upload

Required

toFile

Remote destination file

Required

maven-scm-plugin

The maven-scm-plugin provides integration with Git, SVN, Mercurial, CVS, and other SCM tools for tagging and releasing.

Syntax

Configuration Options

Configuration
Description
Default

connectionUrl

SCM repository URL

Required

developerConnectionUrl

SCM developer URL

Required

tagBase

Base tag URL

Optional

maven-release-plugin

The maven-release-plugin automates the release process, including versioning, tagging, and deployment.

Syntax

Running the Release Process

This process:

  1. Updates the version in pom.xml

  2. Tags the code in SCM

  3. Deploys the release artifact

Configuration Options

Configuration
Description
Default

tagNameFormat

Format for tags

project.artifactId-version

releaseProfiles

Additional Maven profiles to use

None

5. Clean & Site Plugins

maven-clean-plugin

The maven-clean-plugin is responsible for removing the target/ directory created during the build. This ensures that stale or obsolete files don’t affect the next build process.

Deletes all files generated by the previous build in the target/ directory.

Syntax

Configuration Options

Configuration
Description
Default

filesets

Allows you to specify additional files/folders to delete

None

excludeDefaultDirectories

If true, does not delete the default target/ dir

false

maven-site-plugin

The maven-site-plugin is used to generate a complete website for your project using metadata from the pom.xml and additional documentation resources (Markdown, APT, etc.).

Generates HTML pages for project reports, Javadoc, changelogs, dependency reports, etc.

Use

This creates the site in target/site/index.html.

Syntax

Configuration Options

Configuration
Description
Default

reportPlugins

Specifies which reporting plugins to include

Default reports

outputDirectory

Directory where site files will be generated

target/site

inputEncoding

File encoding

UTF-8

Last updated