The pom.xml (Project Object Model) is the heart of every Maven project. Think of it like a recipe card. It tells Maven: who you are, what ingredients (libraries) you need, and how to cook (build) the project. Every Maven project has exactly one pom.xml in the root directory.
Here's a production-ready pom.xml for a Selenium + TestNG + Allure project. This is copy-paste ready — use it as your starting template for any automation project.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- ===== PROJECT IDENTITY (GAV Coordinates) ===== -->
<groupId>com.testerrank</groupId>
<artifactId>banking-portal-automation</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Banking Portal Automation</name>
<description>Selenium automation for TesterRank Banking Portal</description>
<!-- ===== CENTRALIZED VERSION MANAGEMENT ===== -->
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Library versions — change here, updates everywhere -->
<selenium.version>4.18.1</selenium.version>
<testng.version>7.9.0</testng.version>
<allure.version>2.25.0</allure.version>
<aspectj.version>1.9.21</aspectj.version>
<!-- Test execution properties -->
<suiteXmlFile>testng.xml</suiteXmlFile>
<browser>chrome</browser>
<headless>false</headless>
</properties>
<!-- ===== DEPENDENCIES (Libraries your project needs) ===== -->
<dependencies>
<!-- Selenium WebDriver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<!-- WebDriverManager (auto-downloads browser drivers) -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.7.0</version>
</dependency>
<!-- TestNG -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
<!-- Allure TestNG Integration -->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>${allure.version}</version>
<scope>test</scope>
</dependency>
<!-- Apache POI for Excel data-driven testing -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.5</version>
</dependency>
</dependencies>
<!-- ===== BUILD CONFIGURATION ===== -->
<build>
<plugins>
<!-- Maven Compiler Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.12.1</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<!-- Maven Surefire Plugin (runs tests) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<browser>${browser}</browser>
<headless>${headless}</headless>
</systemPropertyVariables>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>| Section | Purpose | Example |
|---|---|---|
| GAV Coordinates | Uniquely identifies your project worldwide | com.testerrank:banking-portal-automation:1.0-SNAPSHOT |
| groupId | Your organization (reverse domain name) | com.testerrank, com.company, org.example |
| artifactId | Your project name | banking-portal-automation, api-test-framework |
| version | Current version (-SNAPSHOT = in development) | 1.0-SNAPSHOT, 2.0.0, 1.0-RELEASE |
| properties | Centralized variables — change once, updates everywhere | ${selenium.version} used across all Selenium deps |
| dependencies | Libraries your project needs | selenium-java, testng, allure-testng |
| build > plugins | Tools that compile and run your project | maven-compiler-plugin, maven-surefire-plugin |
Always use properties for version numbers. Never hardcode "4.18.1" in 5 different places. Put it in <properties> as <selenium.version>4.18.1</selenium.version>, then use ${selenium.version} in dependencies. Update in one place = updates everywhere.
Q: What is pom.xml? What are the key sections?
A: pom.xml is the Project Object Model — the central configuration file for a Maven project. Key sections: (1) GAV coordinates — groupId, artifactId, version — uniquely identify the project. (2) Properties — centralized version numbers and configuration values. (3) Dependencies — all external libraries like Selenium, TestNG, Allure with their versions and scopes. (4) Build plugins — compiler plugin for Java version, Surefire plugin for running tests. Everything Maven needs to build and run the project is defined here.
90% of freshers make this mistake: they edit pom.xml but forget to reload Maven in IntelliJ. After any pom.xml change, click the "Load Maven Changes" notification or right-click pom.xml > Maven > Reload Project. Otherwise IntelliJ won't download the new dependencies.
Key Point: pom.xml is the single source of truth — project identity, dependencies, and build configuration all live here.