Maven Build Life Cycle – Build process in Maven

In this article i will talk about maven build life cycle, that is maven build process.

In my last tutorial. i talked about maven introduction, how to install maven & other things.

Introduction to Maven (A Build Tool) – What is Maven?

How to download and Install Maven in Eclipse IDE?

How to create Maven Project for Selenium in Eclipse IDE?

Okay, so let us talk about maven build life cycle. Maven build process is via command prompt or in eclipse IDE.

Every build follows the life cycle (Write code -> compile -> run test cases -> package -> install).  In the similar way maven has its own build life cycle.

Maven-Build-Life-Cycle consist of below phases –

  1. Validate – (Check if everything is at proper place like POM.xml, if configuration is proper etc)
  2. Compile – (Takes all .java files & create .class files)
  3. Test –  (Where our actual test cases runs)
  4. Package –  (Packages the code, all class files either in jar / war files, depending on what we specify in POM.xml)
  5. Install –  (Install the package in to local maven repository. Note that – Install does not mean installation in to your server like install war in to server. Here it is maven specific. It just put in local maven repository. So, Install is something that helps you to publish your jars in to your local repository so if you have dependency of this jar in another project, it can pull that jar from local repository).
  6. Deploy –  (Deploy does not mean deploying on webserver. This means publish this artifact to remote repository so that other can pull the same. This is more or less same as install phase. We do not use deploy phase mostly until and unless your projects are linked and they have dependency of newly created jar file on another project)

How to run Maven commands?

Maven commands can be run via command prompt or can be via eclipse IDE.

  1. Run Maven Commands from eclipse IDE

Once you have created a maven project & updated you POM.xml with required testng.xml (watch below video to understand how), we can run maven project from eclipse ide. refer below screenshot.

maven build process - Run maven commands from eclipse IDE

You can right click on maven project & then click on “Run As”, You will find multiple options to run your maven projects. Will talks about multiple options in below few para.

2. Another way to run maven commands is from Command prompt.

Once your maven project is ready, Go to command prompt & go to the directory where your maven project is located at.

My maven project is present at – C:\Users\Prakash\workspace\kdf1

So, go to this location & enter the maven command here. Execution should start. Refer below screenshot.

maven build process - Run maven commands from command prompt

So, above is the way how to execute maven commands.

Now what are the maven commands?

  1. mvn clean –> This command is used to clean results from previous build
  2. mvn clean test –> this command is used to clean & then run the test cases (So this include compile as well)
  3. mvn compile –> this will only compile the project (creates .class files only). No Execution.
  4. mvn package –> this will compile, execute & it will creates a package (.jar or war file as specified)
  5. mvn deploy –> this will compile, execute, creates package & will deploy in repository.

.  .  .  .  .  there can be few more commands as well .   .   .   .

This is all about maven build life cycle.

Refer below video for the same –

 

Do post you comments / improvement suggestions. Thanks !!!!!

Leave Comment

Your email address will not be published. Required fields are marked *

Looking for learning Framework Development from Scratch? Lookout for Detailed Framework Development videos on YouTube here -

https://www.youtube.com/automationtalks

Get the Framework code at Github Repo: https://github.com/prakashnarkhede?tab=repositories