Configuration file

Configuration file #

The Project Object Model (POM) #

The root folder of a Maven project normally contains a configuration file called pom.xml. This file provides the information needed to identify and build the project.

Hint. Your IDE can generate the backbone of a pom.xml file (for instance, when creating a Maven project).

For a basic Java project, the pom.xml file usually has the following structure:

<?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>

  <!-- Artifact coordinates for the project -->
  <groupId> XXX </groupId>
  <artifactId> XXX </artifactId>
  <version> XXX </version>

  <!-- Properties of the project -->
  <properties>
    ...
  </properties>

  <!-- Dependencies of the project -->
  <dependencies>
    ...
  </dependencies>

  <!-- Project build specification -->
  <build>
    ...
  </build>
</project>

For instance, here is the skeleton of a minimal pom.xml file for a Java 17 project:

<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>

  <!-- Artifact coordinates for the project -->
  <groupId>it.unibz.pp-23-24</groupId>
  <artifactId>myProject</artifactId>
  <version>1.0-SNAPSHOT</version>

  <!-- Version of Java and character encoding -->
  <properties>
    <maven.compiler.target>17</maven.compiler.target>
    <maven.compiler.source>17</maven.compiler.source>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <!-- No dependency -->
  <dependencies>
  </dependencies>

  <!-- No build specification -->
  <build>
  </build>

</project>

Parent POM, super POM, effective POM #

A POM can inherit properties from a parent POM, via so-called project inheritance. In addition, every POM implicitly inherits from the so-called super POM.

In case of conflict, the values specified in the child POM have precedence over those specified in the parent POM (analogously to inheritance of attributes in Java).

The effective POM of a project is the one induced by the project’s POM and the properties that it inherits from other POMs.

To display the effective POM of a project, from the root of this project, run:

mvn help:effective-pom

Note. Inheritance of configuration (where a project-specific or user-specific configuration may partially overwrite a parent configuration) is not specific to Maven, but used by many programs.