Fork me on GitHub

This plugin available from Maven Central. This means you can simply add it to your pom.xml, specifying your preferred format configuration. For example:

<plugin>
  <groupId>au.com.acegi</groupId>
  <artifactId>xml-format-maven-plugin</artifactId>
  <version>3.3.1</version>
  <executions>
    <execution>
      <id>xml-format</id>
        <goals>
          <goal>xml-format</goal>
        </goals>
      <configuration>
        <!-- configure your formatting preferences here (see link below) -->
        <indentSize>2</indentSize>
      </configuration>
    </execution>
  </executions>
</plugin>

The above will cause mvn package to format all your XML files automatically during any verify phase. You can select a different phase by adding a <phase>someOther</phase> to the <execution> element.

Please see the xml-format:xml-format page for the available configuration options.

You can also configure the plugin to just check formatting, without applying any changes. It will just fail the build if any file doesn't respect the conventions. This is mainly useful for CI, to make sure everyone has checked in formatted files.

<plugin>
  <groupId>au.com.acegi</groupId>
  <artifactId>xml-format-maven-plugin</artifactId>
  <version>3.3.1</version>
  <executions>
    <execution>
      <id>xml-format</id>
      <goals>
        <goal>xml-check</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <!-- configure your formatting preferences here (see link above) -->
    <indentSize>2</indentSize>
  </configuration>
</plugin>

Note that we defined the configuration globally for the plugin, outside of the execution. This allows you to format the files manually from the command line:

mvn xml-format:xml-format