Maven Setup

 

POM.xml Configuration

Learning Outcome

4

Learn to integrate tools like TestNG and Selenium through dependencies

3

Configure groupId, artifactId, and version (GAV coordinates)

2

Learn how to define and manage project dependencies

1

Understand the role of pom.xml as the heart of a Maven project

5

Improve project maintainability using centralized configuration management

 

We know:

  • Basics of Maven and its purpose
  • Understanding of Maven project structure
  • Knowledge of dependencies and JAR files
  • Basics of Java build process (compile → test → package)
  • Understanding of Maven lifecycle phases
  • Familiarity with TestNG/Selenium setup in Java projects
  • Basic knowledge of XML syntax and tags
  • Understanding of GAV (GroupId, ArtifactId, Version) concept
  • Basics of using IDE (Eclipse/IntelliJ) for Maven projects

Think of pom.xml as a restaurant menu + manager system 

 

It decides what items (tools/libraries) are available and how the restaurant runs.

pom.xml is like a smart restaurant manager that decides:

  • what ingredients are needed

  • how the dish (project) is prepared

  • and ensures everything runs smoothly without confusion

Why pom.xml Used

pom.xml helps Maven run and manage the project smoothly.

To store all project configuration in one place

To manage dependencies (libraries like Selenium, TestNG)

To define project details (name, version, etc.)

To control build process (compile, test, package)

To make the project easy to manage and maintain

  • To add plugins for build and testing

What is  pom.xml?

POM (Project Object Model) is the core configuration file of a Maven project.

It tells Maven:

What the project is

What it needs (dependencies)

How to build it

How to run tests

Central control unit

Configuration file

Instruction manual for Maven

It acts as:

The Maven Build Lifecycle is a structured sequence of phases that defines how a Java project is built, tested, verified, and deployed in an automated way

 Maven builds, tests, and deploys the project step by step automatically.

 

Steps to Create a Maven Project

Add Dependencies in pom.xml

  • Add required libraries (TestNG, Selenium, etc.)

  • Save file → Maven automatically downloads dependencies

Right-click project → Run As → Maven test

 

 

Use command:   mvn clean test

Run Maven Project

OR

Maven Commands

mvn clean test 

Cleans and runs all tests

mvn clean install 

Cleans, tests, and installs project

mvn clean

Removes target folder (old build files)

mvn compile 

Compiles source code

mvn test

 Runs test cases (TestNG/JUnit)

mvn package

Creates JAR/WAR file

mvn install 

 Saves build in local repository (.m2)

mvn deploy

Uploads build to remote repository

Maven commands are used to build, test, package, and manage Java projects automatically.

Summary

4

Supports build lifecycle phases like compile, test, and package

3

Manages dependencies using pom.xml

2

Used to automate Java project setup and execution

1

Maven is a build and dependency management tool

Quiz

Which file is used to manage dependencies in Maven?

A.config.xml

B.build.xml

C.pom.xml

D.settings.xml

Quiz-Answer

Which file is used to manage dependencies in Maven?

A.config.xml

B.build.xml

C.pom.xml

D.settings.xml