Skip to content

SortPom and Build Servers

Björn Ekryd edited this page Oct 20, 2020 · 4 revisions

Configuration with Build Servers

Most Build Servers do not modify the code and commit the code, so it does not make sense to let the server use the sort goal with SortPom. I recommend that the Build Server uses the verify goal instead.

Recommended configuration

...
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    ...
  </properties>

...
      <plugin>
        <groupId>com.github.ekryd.sortpom</groupId>
        <artifactId>sortpom-maven-plugin</artifactId>
        <version>2.12.0</version>
        <configuration>
          <encoding>${project.build.sourceEncoding}</encoding>
          <keepBlankLines>true</keepBlankLines>
          <predefinedSortOrder>custom_1</predefinedSortOrder>
          <sortDependencies>scope</sortDependencies>
          <sortProperties>true</sortProperties>
          <verifyFail>stop</verifyFail>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>verify</goal>
            </goals>
            <phase>validate</phase>
          </execution>
        </executions>
      </plugin>
...

The plugin is most likely configured in a profile that is activated by the Build Server.

What will it do?

  • The pom file will be checked during build startup (validate phase) and the plugin will stop the build if the pom file is not sorted.
  • Use a predefined sort order which I prefer myself (parent, basic info and properties on top; dependencies and plugins in the middle; other info and profiles last)
  • Use the explicit encoding UTF-8
  • The pom properties must be sorted
  • The dependencies must be sorted by scope (to gather test dependencies together)
  • This makes sure that the developers must sort the pom file before the check in any changes.

This configuration is combined with an ordinary configuration of SortPom that will sort the pom file during the build phase.

The plugin can also be configured in the pluginManagement section and have one plugin entry (with sort) in the build section and one plugin entry (with verify) in the profiles section.

Clone this wiki locally