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 –
- Validate – (Check if everything is at proper place like POM.xml, if configuration is proper etc)
- Compile – (Takes all .java files & create .class files)
- Test – (Where our actual test cases runs)
- Package – (Packages the code, all class files either in jar / war files, depending on what we specify in POM.xml)
- 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).
- 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.
-
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.
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.
So, above is the way how to execute maven commands.
Now what are the maven commands?
- mvn clean –> This command is used to clean results from previous build
- mvn clean test –> this command is used to clean & then run the test cases (So this include compile as well)
- mvn compile –> this will only compile the project (creates .class files only). No Execution.
- mvn package –> this will compile, execute & it will creates a package (.jar or war file as specified)
- 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 !!!!!