What is pom.xml and what is it used for?
Short answer
pom.xml is the configuration file of a Maven Java project. It tells Maven the project's name and version, which dependencies (libraries) it needs, and how to build it. It's the Java equivalent of package.json in Node.js or requirements.txt in Python.
Explained in simple words
Imagine you're cooking a dish. The pom.xml is your recipe card: it lists the ingredients (dependencies like Spring Boot or a MySQL driver), their exact versions, and the cooking steps (compile, test, package). Anyone with the recipe card can cook the exact same dish — that's why a pipeline can build the app on any machine.
What's inside a pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<!-- 1. Who this project is -->
<groupId>com.devopsshack</groupId>
<artifactId>orders-service</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging> <!-- jar or war -->
<!-- 2. Which libraries it needs -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>3.3.4</version>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.4.0</version>
</dependency>
</dependencies>
<!-- 3. How to build it -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
| Part | Meaning |
|---|---|
groupId |
The organisation, usually a reversed domain (com.devopsshack) |
artifactId |
The project name (orders-service) |
version |
The project version (1.0.0); -SNAPSHOT means "still in development" |
packaging |
The output type: jar or war |
dependencies |
Libraries Maven downloads automatically |
build/plugins |
Extra build steps, such as creating a runnable Spring Boot JAR |
Where dependencies come from
Maven downloads them from Maven Central (the public repository) or from your company's private repository, such as Nexus or JFrog Artifactory. Downloaded files are cached in ~/.m2/repository so they aren't downloaded again.
What to say in the interview
"pom.xml is Maven's project file. It defines the project coordinates — groupId, artifactId and version — the packaging type, the dependencies the app needs and the build plugins. When we run mvn clean package in the pipeline, Maven reads pom.xml, downloads dependencies from Maven Central or our Nexus repository, compiles, runs tests and produces the JAR or WAR in the target/ folder."
Follow-up questions you may get
- What's the Gradle equivalent?
build.gradle(orbuild.gradle.kts). - How do you point Maven at Nexus? Configure a mirror and credentials in
~/.m2/settings.xml. - What does SNAPSHOT mean? A development version that can change; release versions like
1.0.0should never change.