EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Maven Tutorial Maven Phases
Secondary Sidebar
Maven Tutorial
  • Maven Basic and advance
    • What is Maven
    • How to Install Maven
    • Maven Commands
    • Maven GroupId
    • Maven WAR Plugin
    • Maven Build Command
    • Maven Failsafe Plugin
    • Maven Profile
    • IntelliJ Maven
    • Maven Enforcer Plugin
    • Maven Javadoc Plugin
    • Maven WAR Plugin
    • Maven Build Command
    • Maven GroupId
    • Maven Force Update
    • Maven Encrypt Password
    • Maven Environment Variables
    • AssertJ Maven
    • Maven Run Single Test
    • Maven kafka-clients
    • Maven Quickstart Archetype
    • Maven Install Dependencies
    • Maven XMLBeans
    • Maven Local Repository
    • Maven Versions
    • Maven Jar Plugin
    • Maven Assembly Plugin
    • Maven exec plugin
    • Maven Central Repository
    • Maven Surefire
    • Maven Deploy
    • Maven Phases
    • Maven Archetype
    • Maven Skip Test
    • Maven Dependency Scope
    • Maven Shade Plugin
    • Maven Repository Spring
    • Maven Eclipse Plugin
    • Maven Exclude Dependency
    • Maven Life Cycle
    • Maven Repository
    • Maven POM File
    • Maven Plugins
    • What is Maven Plugins
    • Maven Interview Questions
    • Maven Flags
    • Maven Project
    • Maven Settings.XML

Maven Phases

By Payal UdhaniPayal Udhani

Maven Phases

Introduction to Maven Phases

Maven is a building tool that can also be used for many other purposes such as dependency management, unit testing, project documentation and deployment. Here we will see about the different phases involved in the build lifecycles of maven. If a person is aware of a few commands that are necessary for building a project and executing the phases. He can build any maven project easily as POM makes sure that all other dependencies are acquired and desired results are the output. While executing any phase, it is necessary to keep in mind that the only specified phase is not run, all the phases prior to the specified phase and the mentioned one are executed.

Build Lifecycles and Phases

Maven provides us with three build lifecycles that are built-in. These build lifecycles are default, clean and site. Each of them has some purpose and usage and also contains many build phases by which it is defined. The default build lifecycle helps in handling and maintaining the deployment of the project. The second build lifecycle i.e clean build lifecycle helps in cleaning the project while the site build lifecycle is responsible for document creation at the project’s site. Each of these built-in build lifecycles is made up of different phases. The default lifecycle is made up of 23 phases, clean lifecycle of 3 phases and site lifecycle of 4 phases.

For example, the default build life cycle is made of some of the following phases that act as different stages in the lifecycle.

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,754 ratings)
  • Validate phase: This phase and stage makes sure that all the necessary things are present and the project is correct in every format required.
  • Compile phase: In this phase, the source code of the project is compiled.
  • Test phase: In this phase, the source code is being tested for some basic test cases that do not include packing or deployment in it with the help of any unit testing framework.
  • Package phase: Takes the compiled code and package in its distributable format, such as a JAR.
  • Verify phase : To make sure that the quality is maintained an integration testing on the current source code is being made in this phase.
  • Install phase: There is often a necessity to add a dependency of a certain project in some other project. This phase makes sure that the project package is properly installed for making other projects available with adding the dependency of the current project being built.
  • Deploy phase: In this phase, the build is completed and the current project is being copied to the remote repository. This makes the built project available for other projects to add as dependency or developers.

All the phases of each of the three build lifecycles are executed in the sequential format. In the default build lifecycle, the project is primarily validated for its correctness and made sure that all the requirements are met correctly after which the source code is compiled and then unit testing is done that is further followed with integration testing and installing the packaged project on local repository after which the project is made available to other projects and developers by deploying it on the remote repository.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Maven Commands

We can select any phase that we wish to run according to our convenience and necessity and fire the command from the command line using the below format.

1. mvn package

The above command will create a jar or war file for you depends on the type of project and language you are using. If your application is a java project then java archives i.e jar will be generated and for web applications web archives i.e wars will be created. Depending on your purpose you can fire different commands and run different phases such as for performing unit testing you will fire mvn test command and so on. Whenever you execute a certain command then all the phases previous to it in the sequence of the phases will also execute.

For example, whenever you fire the mvn verify command then all the phases before it in the sequence that are validated, compile, test and package will also get executed. Hence, whenever you want to execute a certain phase just choose the last phase up to which you want to perform the build lifecycle and all the previous phases will also get executed.

Note that certain phases cannot be called from the command-line.

2. mvn clean deploy

Whenever you want to clean the project and deploy your project or artifact into the repository where it can be shared further then you can use this command. This command can also be used when your project is made up of sub projects and contains multiple projects in it. In this case, each sub project is cleaned and deployed i.e clean and deploy build cycles are executed for each of them. This is called a multi-module structure that is supported by maven.

Plugin Goals

  • The build lifecycle or task is further broken down into granular level by breaking each of the phases of lifecycle into multiple plugin goals which are the small task responsible for managing and building the artifact/project.
  • A single plugin can be bound to none, one or many build phases.
  • Whenever it does not belongs to any of the phases then it can be executed individually outside the lifecycle build process by invoking it directly.
  • From Maven 2.0.5 onwards, the POM decides the order in which the multiple plugins belonging to the same phase are executed.

Conclusion – Maven Phases

Maven has three built-in build lifecycles named default, clean and deploy. Each of the build lifecycles is made up of different phases that are even referred to as stages that are executed in the sequential order and perform some specific task. Each phase is further made up of one or more goals with which it is bound that help in managing and building the project.

Recommended Articles

This is a guide to Maven Phases. Here we discuss the introduction to Maven Phases with build lifecycles and phases, maven commands and plugin goals. You may also have a look at the following articles to learn more –

  1. Maven Life Cycle
  2. Maven Repository
  3. Maven POM File
  4. Maven Plugins
Popular Course in this category
Maven Training (4 Courses, 6 Projects)
  4 Online Courses |  6 Hands-on Project |  26+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more