In Maven 2, this notion is standardized into a set of well-known and well-defined lifecycle phases(see figure). Instead of invoking plug-ins, the Maven 2 developer invokes a lifecycle phase:
$mvn compile. All the dependencies, goals, tasks, plugins which belong to this life cycle phase will be invoked otherwise not.
For example if Trinidad report plugin is required to be executed during test phase then it can be configured in below way
Some useful Maven 2 lifecycle phases are the following:
- generate-sources: Generates any extra source code needed for the application, which is generally accomplished using the appropriate plug-ins
- compile: Compiles the project source code
- test-compile: Compiles the project unit tests
- test: Runs the unit tests (typically using JUnit) in the src/test directory
- package: Packages the compiled code in its distributable format (JAR, WAR, etc.)
- integration-test: Processes and deploys the package if necessary into an environment where integration tests can be run
- install: Installs the package into the local repository for use as a dependency in other projects on your local machine
- deploy: Done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects
The lifecycle phase invokes the plug-ins it needs to do the job. Invoking a lifecycle phase automatically invokes any previous lifecycle phases as well. Since the lifecycle phases are limited in number, easy to understand, and well organized, becoming familiar with the lifecycle of a new Maven 2 project is easy.
All Maven Default Lifecycle Phases
- prepare-package (maven 2.1+)
There are a couple key concepts to be aware of with maven lifecycles. First off, if we call a particular phase via a maven command, such as “mvn compile”, all phases up to and including that phase will be executed. So, in the case of “mvn compile”, we would actually go through the validate, generate-sources, process-sources, generate-resources, process-resources, and compile phases. The second main concept to be aware of in regards to lifecycles is that, based on the packaging of a project (jar, war, ear, etc), different maven goals will be bound to different phases of the maven lifecycle.