In this article we will be looking at the basics on Maven build life cycle and their phases.
Maven is based around the central concept of a build lifecycle. What this means is that the process for building and distributing a particular artefact (project) is clearly defined.
For a person building a Maven project, the only criteria is to be aware of a small set of commands used to build any projects and the POM will ensure to get the desired results based on these commands.
There are three built-in build lifecycles
- default – handles the project deployment
- clean – performs the project cleaning
- site – deals with project site documentation
Maven Phases
Maven build phase represents a stage in the lifecycle. Each lifecycle has its own list of build phases.
For Ex: The default lifecycle comprises of the following phases.
validate
: validate the project is correct and all necessary information is availablecompile
: compile the source codetest
- test the compiled source code using a suitable unit testing framework.package
– package the compiled code into a distributable format, such as a JAR.- integration-test – run integration tests on the packaged binaries
verify
- run any checks on results of integration tests to ensure quality criteria's are metinstall
- install the package into the local repositorydeploy
- done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.
You can find an exhaustive list of the lifecycle phases by clicking here
These lifecycle phases are executed sequentially to complete the default
lifecycle. Considering the above example, Maven will first validate the project, compile the source code, run unit tests, package the binaries (e.g. jar), run integration tests, verify the integration tests, install the verified package to the local repository, then deploy the installed package to a remote repository.
Maven Goals:
Each Maven phases will have a sequence of goals which are meant to perform specific tasks.
Below listed are some of the goals that are bound to their relevant phases.
Phase | plugin:goal |
compile | compiler:compile |
test | surefire:test |
package | jar:jar |
install | install:install |
deploy | deploy:deploy |
Maven Plugins
Plugins are artefacts that provide goals to Maven. However these goals may or may not be bounded to the same phase.
For example: The Failsafe Plugin is used during the integration-test
and verify
phases of the build lifecycle to execute the integration tests of an application.
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M4</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
As we can see, the Failsafe plugin has two main goals configured here:
- integration-test: run integration tests
- verify: verify if the integration tests are passed
That’s all about a brief overview on the Maven Goals & Phases. Please feel free to drop me a comment in case if you liked my article. In my next article will be looking at Maven installation & project creation from command-line and also from eclipse.
Technorati Tags: Maven goals,maven goals and phases,maven tutorial,mvn tutorial,mvn phases,mvn goals,maven plugins,mvn plugin,java Build tool,maven,automation,m2,apache maven
No comments: