Maven - Maven Build Life Cycle - maven tutorial




maven tutorial tags : apache maven , maven repository , maven central

How to Build Maven Life Cycle?

  • The sequence of steps which is defined in order to execute the tasks and goals of any maven project is known as build life cycle in maven.
  • learn maven tutorial - maven project - apache maven - maven architecture - Apache Maven example programs

    learn maven tutorial - maven project - apache maven - maven architecture - Apache Maven example programs

  • Maven 2.0 version is basically a build life cycle oriented and clearly says that these steps are well defined to get the desired output after the successful execution of the build life cycle.
  • Maven comes with 3 built-in build life cycles as shown below :
    • Clean - this phase involves cleaning of the project (for a fresh build & deployment)
    • Default - this phase handles the complete deployment of the project
    • Site - this phase handles the generating the java documentation of the project.
    learn maven tutorial - maven project - apache maven - maven lifecycle build types - Apache Maven example programs

    learn maven tutorial - maven project - apache maven - maven lifecycle build types - Apache Maven example programs

  • Now we will dig more into the detailed phases involved in the above mentioned built-in build life cycles.
 Maven Lifecycle

Learn Maven Tutorial - Maven Lifecycle - Maven Example

Build Life Cycle of clean phase

  • This clean phase is used to clean up the project and make it ready for the fresh compile and deployment.
  • The command used for the same is mvn post-clean.
  • When this command is invoked, maven executes the below tasks via executing the below commands internally:
    • mvn pre-clean
    • mvn clean
    • mvn post-clean
  • This maven’s clean is a goal and on executing it cleans up the output directory (target folder) by deleting all the compiled files.

NOTE :

  • Whenever a maven command for any life cycle is invoked, maven executes the phases till and up to the invoked phase.
  • E.g. when 'mvn clean' is invoked, maven will execute only the phase clean.
  • But, no compile/deployment/site phase is invoked.
Maven Build Life Cycle1

Build Lifecycle (Default)

  • Below is the list of phases in the build lifecycle (default) of maven. These phases will be invoked through the maven commands.
Lifecycle Phase Description
validate Validates whether project is correct and all necessary information is available to complete the build process.
initialize Initializes build state, for example set properties
generate-sources Generate any source code to be included in compilation phase.
process-sources Process the source code, for example, filter any value.
generate-resources Generate resources to be included in the package.
process-resources Copy and process the resources into the destination directory, ready for packaging phase.
compile Compile the source code of the project.
process-classes Post-process the generated files from compilation, for example to do bytecode enhancement/optimization on Java classes.
generate-test-sources Generate any test source code to be included in compilation phase.
process-test-sources Process the test source code, for example, filter any values.
test-compile Compile the test source code into the test destination directory.
process-test-classes Process the generated files from test code file compilation.
test Run tests using a suitable unit testing framework(Junit is one).
prepare-package Perform any operations necessary to prepare a package before the actual packaging.
package Take the compiled code and package it in its distributable format, such as a JAR, WAR, or EAR file.
pre-integration-test Perform actions required before integration tests are executed. For example, setting up the required environment.
integration-test Process and deploy the package if necessary into an environment where integration tests can be run.
post-integration-test Perform actions required after integration tests have been executed. For example, cleaning up the environment.
verify Run any check-ups to verify the package is valid and meets quality criterias.
install Install the package into the local repository, which can be used as a dependency in other projects locally.
deploy Copies the final package to the remote repository for sharing with other developers and projects.
maven tutorial tags : apache maven , maven repository , maven central

Site Lifecycle (site)

  • Apart from cleaning, compiling the source code, building a deployable format of the application, maven has phase which does more than these phases.
  • This phase is one of the vital features provided by maven which generates the detailed documentation of any java project.
  • This project documentation has a dedicated phases involved as listed below :
    • pre-site
    • site
    • post-site
    • site-deploy
  • The command used in maven to generate javadocs for a given project is 'mvn site'.
  • Basically, when this command is invoked, maven calls 'Doxia' document generation and other report generating plugins.
  • Doxia is basically a framework used for content generation by maven. This generates contents both in static and dynamic ways.
Maven Build Life Cycle2
learn maven tutorial - maven project - apache maven - maven architecture pom file - Apache Maven example programs

learn maven tutorial - maven project - maven architecture pom file - Apache Maven example programs


Wikitechy provides an indepth knowledge on the below maven tutorial items such as maven download , maven install , maven goals , maven build , maven commands , maven plugin , maven search , maven eclipse , maven deploy , eclipse maven , maven junit , maven java , hibernate maven , maven project , java maven , maven version , maven proxy , maven 2 , maven pom , maven eclipse plugin , maven java version , maven properties , maven install windows , how to create maven project in eclipse , eclipse maven plugin , maven dependencies , what is maven in java , maven apache , maven project structure , how to install maven in eclipse

Related Searches to Maven Build Life Cycle