Hey BugHunters, In this video we are going to discuss Maven Lifecycle Tutorial, What is Maven, Maven Goals, Phases in depth.Enter your text here...
🔥 Join the 30 Days of API Testing with RestAssured
🔥 Download Maven CheatSheet - https://scrolltest.com/ra/day11
What is Maven?
Maven is a build automation tool used primarily for Java projects. Maven can also be used to build and manage projects written in C#, Ruby, Scala, and other languages. Enter your text here...
Maven is a Java tool, so you must have Java installed in order to proceed.
First, download Maven and follow the installation instructions. After that, type the following in a terminal or in a command prompt:
$ mvn --version
Creating a Project
Type this in command line -
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
What is Maven Build Lifecycle?
- validate - validate the project is correct and all necessary information is available
- compile - compile the source code of the project
test - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
- package - take the compiled code and package it in its distributable format, such as a JAR.
- verify - run any checks on results of integration tests to ensure quality criteria are met
- install - install the package into the local repository, for use as a dependency in other projects locally
- deploy - done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.
What is Maven Build Goals
A build phase is made up of a set of goals. Maven goals represent a specific task that contributes to the building and managing of a project.
Sometimes, a maven goal is not bound to a build phase. We can execute these goals through the command line.
The syntax to execute a goal is:
$ mvn plugin-prefix:goal
$ mvn plugin-group-id:plugin-artifact-id[:plugin-version]:goal
Here is an example to execute the dependency tree goal from the command line. It’s not part of any build phases.
There are two other Maven lifecycles of note beyond the default list above. They are
- clean: cleans up artifacts created by prior builds
- site: generates site documentation for this project
Phases are actually mapped to underlying goals. The specific goals executed per phase is dependant upon the packaging type of the project. For example, package executes jar:jar if the project type is a JAR, and war:war if the project type is - you guessed it - a WAR.
An interesting thing to note is that phases and goals may be executed in sequence.
mvn clean dependency:copy-dependencies package
This command will clean the project, copy dependencies, and package the project (executing all phases up to package, of course).
Generating the Site