Format Maven POM.xml — Dependencies, Plugins, and Profiles

Format and structure Maven POM.xml files for readability. Learn the standard POM element ordering, dependency management, plugin configuration, and profile organization.

Configuration

Detailed Explanation

Formatting Maven POM.xml

The Maven POM (Project Object Model) is the fundamental XML configuration file for Maven-based Java projects. A well-formatted POM file is essential for team collaboration and project maintenance.

Standard POM Structure

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

  <groupId>com.example</groupId>
  <artifactId>my-project</artifactId>
  <version>1.0.0</version>
  <packaging>jar</packaging>

  <properties>
    <java.version>17</java.version>
    <spring.version>6.1.0</spring.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>${spring.version}</version>
    </dependency>
  </dependencies>
</project>

Recommended Element Order

The Maven documentation recommends a specific ordering of top-level elements:

  1. modelVersion
  2. parent
  3. groupId, artifactId, version, packaging
  4. name, description, url
  5. properties
  6. dependencyManagement
  7. dependencies
  8. build (plugins, resources)
  9. profiles

Following this convention makes POMs predictable across projects.

Dependency Formatting

Each dependency block should be consistently indented. Group dependencies logically: compile dependencies first, then test dependencies, then provided/runtime:

<dependencies>
  <!-- Compile dependencies -->
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
  </dependency>

  <!-- Test dependencies -->
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <scope>test</scope>
  </dependency>
</dependencies>

Plugin Configuration

Build plugins can carry complex configuration blocks. Proper formatting prevents configuration errors:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.11.0</version>
      <configuration>
        <source>17</source>
        <target>17</target>
      </configuration>
    </plugin>
  </plugins>
</build>

Multi-Module POMs

Parent POMs with <modules> sections benefit greatly from formatting, as they coordinate multiple child projects and can become complex with inherited dependency management and plugin management sections.

Use Case

Maven POM formatting is essential for Java development teams reviewing dependency changes in pull requests, resolving merge conflicts in POM files, auditing dependency versions for security vulnerabilities, and onboarding new developers who need to understand the project's build configuration.

Try It — XML Formatter

Open full tool