pom.xml: coordinates, packaging and properties
35 min · Beginner
Need help? Ask a tutor on WhatsApp (opens in a new tab)A first pom.xml looks like noise, and one missing line, such as the Java version, breaks the build in confusing ways. A small pom is only about fifteen lines, and each line has one job.
Reading a minimal pom.xml line by line
A POM (Project Object Model) is the XML file pom.xml that describes a Maven project: its name, what it builds, its settings and its libraries.
Below is a complete minimal pom for a project called price-check. Read it from top to bottom: the XML header, the project wrapper, the coordinates, the packaging and the properties.
Example 1 · pom.xml: a complete minimal pom
Runs in: the price-check Maven 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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.shoplite</groupId> <artifactId>price-check</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <properties> <maven.compiler.release>17</maven.compiler.release> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties></project>(The pom itself prints nothing. Examples 2 and 6 build this project.)
What this code does
- Read it top to bottom: XML header,
projectwrapper,modelVersion, the three coordinates,packaging, thenproperties. - With no
<dependencies>, this project uses only the JDK. That is still a complete, buildable pom.
XML is text made of tags: <version>1.0-SNAPSHOT</version> is an element called version with the value 1.0-SNAPSHOT. Every opening tag needs a matching closing tag with the same spelling, including upper and lower case.
The long xmlns and schemaLocation attributes only tell editors which tags are allowed, so you copy them as they are. <modelVersion>4.0.0</modelVersion> is the pom format version and is always 4.0.0 for Maven 3. Libraries go in <dependencies>, the next lesson.
Coordinates: groupId, artifactId and version
Coordinates are the three values that name a project or library exactly: groupId, artifactId and version, written together as org.apache.commons:commons-text:1.15.0. They are also called GAV.
The price-check pom holds three coordinates. Maven can print each one back, and it builds the JAR name from them.
Example 2 · Coordinates as Maven sees them, and the JAR name
Runs in: a terminal in the price-check Maven project
mvn -q help:evaluate "-Dexpression=project.groupId" -DforceStdoutmvn -q help:evaluate "-Dexpression=project.artifactId" -DforceStdoutmvn -q help:evaluate "-Dexpression=project.version" -DforceStdoutmvn -q help:evaluate "-Dexpression=project.packaging" -DforceStdoutmvn -q packagels target/*.jar$ mvn -q help:evaluate "-Dexpression=project.groupId" -DforceStdout com.shoplite $ mvn -q help:evaluate "-Dexpression=project.artifactId" -DforceStdout price-check $ mvn -q help:evaluate "-Dexpression=project.version" -DforceStdout 1.0-SNAPSHOT $ mvn -q help:evaluate "-Dexpression=project.packaging" -DforceStdout jar $ mvn -q package $ ls target/*.jar target/price-check-1.0-SNAPSHOT.jar
What this code does
- The JAR is named
artifactId-version.jar:price-check-1.0-SNAPSHOT.jar. The groupId does not appear in the file name; it is used to store and find the JAR in the local repository. - The first run of
help:evaluatedownloads the help plugin;-qhides that log, so only the value is printed.
Example 3 · Mistakes Maven reports before building: no version, misspelt tag
Runs in: a terminal in the price-check Maven project
mvn compilepom.xml without its <version> line: $ mvn compile [ERROR] [ERROR] Some problems were encountered while processing the POMs: [ERROR] The build could not read 1 project -> [Help 1] [ERROR] [ERROR] The project com.shoplite:price-check:[unknown-version] (C:\Users\asha\projects\price-check\pom.xml) has 1 error [ERROR] 'version' is missing. @ line 4, column 110 pom.xml with <artifactId>price-check</artifactID>: $ mvn compile [ERROR] [ERROR] Some problems were encountered while processing the POMs: [ERROR] The build could not read 1 project -> [Help 1] [ERROR] [ERROR] The project (C:\Users\asha\projects\price-check\pom.xml) has 1 error [ERROR] Non-parseable POM C:\Users\asha\projects\price-check\pom.xml: end tag name </artifactID> must be the same as start tag <artifactId> from line 8 (position: TEXT seen ...<artifactId>price-check</artifactID>... @8:41) @ line 8, column 41 -> [Help 2]
What this code does
- "'version' is missing" names the problem; the line and column point at the
<project>tag that should contain it. - "Non-parseable POM" means the XML itself is broken. Tag names are case-sensitive, so
</artifactID>does not close<artifactId>.
groupId is the owner, a reversed domain such as com.shoplite or org.apache.commons. artifactId is the project name in lower case with hyphens, no spaces. version is numbers with dots, plus -SNAPSHOT while the project is still changing. No two libraries on Maven Central share all three values, so one GAV points to exactly one JAR.
Maven checks the pom before it builds anything. A missing coordinate or a misspelt tag stops the build at once with a message that names the line.
Predict the output
Name the JAR
Pick the JAR file name that appears in target after mvn package.
Round 1 of 2
A new project, still being built.
SNAPSHOT versus release versions
A SNAPSHOT version, such as 1.0-SNAPSHOT, means work in progress. The code behind it keeps changing, so two builds of the same SNAPSHOT may differ. New projects start as SNAPSHOT.
Changing only the <version> line changes the JAR name. Build the project as 1.0-SNAPSHOT, then as 1.0.0, and compare.
Example 4 · From 1.0-SNAPSHOT to the 1.0.0 release
Runs in: a terminal in the price-check Maven project
mvn -q packagels target/*.jar# edit pom.xml: <version>1.0.0</version>mvn -q packagels target/*.jar$ mvn -q package $ ls target/*.jar target/price-check-1.0-SNAPSHOT.jar $ mvn -q package $ ls target/*.jar target/price-check-1.0-SNAPSHOT.jar target/price-check-1.0.0.jar
What this code does
- Changing only
<version>changes the JAR name, because the name is built from the coordinates. - The old SNAPSHOT JAR is still in
target: Maven never deletes old output on its own.mvn clean, in the lifecycle lesson, emptiestargetfirst.
A release version, such as 1.0.0, is a promise that the code behind it will never change. Libraries on Maven Central are releases: depend on commons-text:1.15.0 today and get the same JAR in five years.
To release, remove -SNAPSHOT, build and tag that commit, then move on to the next SNAPSHOT, such as 1.1.0-SNAPSHOT. Many teams number releases as major.minor.patch: patch for bug fixes, minor for new features, major for changes that can break users.
packaging: jar (default), war and pom
<packaging> is the pom element that says what kind of file the build produces. The default is jar, a Java archive for apps and libraries.
You may leave the line out, because jar is the default, but <packaging>jar</packaging> makes the pom easier to read. mvn help:evaluate prints any value Maven worked out from your pom, so you can check the packaging in one command.
mvn -q help:evaluate "-Dexpression=project.packaging" -DforceStdoutYou will meet two other values. war (web archive) is for web apps deployed into a separate server such as Tomcat; the Spring Boot apps in this course are plain jars that start their own server. pom means the project builds no JAR at all and only groups or configures other projects, as a parent pom of a multi-module project does.
properties: maven.compiler.release 17 and UTF-8 sources
maven.compiler.release is the property that sets the Java version Maven compiles for. With 17, the code may use Java 17 features and the classes run on Java 17 or newer.
Leave it out and Maven 3.9 still compiles for Java 8, so a record or a text block fails to compile. See that failure first, then the fix.
Example 5 · Mistake: no properties, so Maven compiles for Java 8
Runs in: a terminal in the price-check Maven project
mvn compilepom.xml without <properties>; PriceCheck.java declares a record $ mvn compile [INFO] Scanning for projects... [INFO] ----------------------< com.shoplite:price-check >---------------------- [INFO] Building price-check 1.0-SNAPSHOT [INFO] from pom.xml [INFO] --------------------------------[ jar ]--------------------------------- [INFO] --- resources:3.4.0:resources (default-resources) @ price-check --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory C:\Users\asha\projects\price-check\src\main\resources [INFO] --- compiler:3.15.0:compile (default-compile) @ price-check --- [INFO] Recompiling the module because of changed source code. [WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent! [INFO] Compiling 1 source file with javac [debug target 1.8] to target\classes [INFO] ------------------------------------------------------------- [WARNING] COMPILATION WARNING : [INFO] ------------------------------------------------------------- [WARNING] bootstrap class path not set in conjunction with -source 8 [WARNING] source value 8 is obsolete and will be removed in a future release [WARNING] target value 8 is obsolete and will be removed in a future release [WARNING] To suppress warnings about obsolete options, use -Xlint:-options. [WARNING] /C:/Users/asha/projects/price-check/src/main/java/com/shoplite/app/PriceCheck.java:[7,5] 'record' may become a restricted type name in a future release and may be unusable for type declarations or as the element type of an array [INFO] 5 warnings [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] /C:/Users/asha/projects/price-check/src/main/java/com/shoplite/app/PriceCheck.java:[7,5] records are not supported in -source 8 (use -source 16 or higher to enable records) [INFO] 1 error [INFO] BUILD FAILURE
What this code does
- "javac [debug target 1.8]" shows the default: Java 8. Records arrived in Java 16, so line 7 fails with "records are not supported in -source 8".
- The two "platform encoding" warnings are the missing
project.build.sourceEncoding. On this computer the platform encoding happens to be UTF-8, but on another one it may not be.
Example 6 · With release 17 and UTF-8: compile and run
Runs in: the price-check Maven project with the pom from Example 1
package com.shoplite.app;
import java.math.BigDecimal;
public class PriceCheck {
record Product(String sku, String name, BigDecimal price) { }
public static void main(String[] args) { Product p = new Product("BK-101", "Java notebook, 200 pages", new BigDecimal("149.00")); System.out.println(p.sku() + " | " + p.name() + " | Rs " + p.price()); }}$ mvn -q compile $ java -cp target/classes com.shoplite.app.PriceCheck BK-101 | Java notebook, 200 pages | Rs 149.00
What this code does
- With
<maven.compiler.release>17</maven.compiler.release>the log says "javac [debug release 17]" and the record compiles. BigDecimal("149.00")keeps the rupee amount exact; the encoding warnings are gone because the pom now names UTF-8.
<properties> holds named settings that Maven and its plugins read; you can add your own and use them anywhere in the pom as ${name}. A second property, project.build.sourceEncoding set to UTF-8, tells Maven how to read your source files, so a ₹ or a Hindi word in a string means the same on every computer.
release also stops you from calling JDK methods that do not exist in Java 17, even when you build with JDK 25. That is why it is preferred over the older pair maven.compiler.source and maven.compiler.target, which some IDE wizards still write.
Fix the error
Fix the Java version
The code uses a record, but the build says the Java level is too old.
Pick the line that makes the record compile.
Error
error: records are not supported in -source 8 (use -source 16 or higher to enable records)
Next step
Check your understanding
11 quick questions