Skip to content
Petkomat edited this page Apr 16, 2024 · 4 revisions

Ignore Sections

SortPom always sorts the whole pom.xml by default and this is the recommended behavior. The plugin can be configured with parameters to fit most needs and if that fails then custom sort order files can be written. But when everything else is unsuccessful, sections in the pom.xml can be excluded from the sorting process.

How to ignore a section

Use the xml processing commands <?SORTPOM IGNORE?> and <?SORTPOM RESUME?>.

Example:

        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <?SORTPOM IGNORE?>
            <version>2.0</version><!--$NO-MVN-MAN-VER$ -->
            <?SORTPOM RESUME?>
        </dependency>

Normally SortPom would place the comment on the next line.

If the comment absolutely needs to stay on the same line then the <?SORTPOM IGNORE?> and <?SORTPOM RESUME?> instructions can be used to create an ignored section.

How does it work

The ignored section will be completely removed before the sorting and then inserted again after the sorting is done. What are the consequences?

  • The ignored section must be at the same xml level. Otherwise SortPom will just see a broken xml.
  • The IGNORE instruction must always be followed by a RESUME instruction.
  • The ignored sections cannot be nested.
  • If the pom.xml is really unsorted, the ignored section can end up in unexpected places. Please sort the pom.xml once without ignored sections first.

Critical dependencies to the top

There is a special trick to getting a critical dependency to the top of dependencies, using ignored sections. This can be used when dependencies are sorted, but one dependency really needs to be placed first due to class loading problems.

  <dependencies>
    <dependency>
      <?SORTPOM IGNORE?>
      <groupId>org.jmockit</groupId>
      <artifactId>jmockit</artifactId>
      <scope>test</scope>
      <?SORTPOM RESUME?>
    </dependency>
    <dependency>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-junit-jupiter</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

If the plugin uses sortDependencies configuration and one dependency is wrapped inside with ignored sections, then that dependency will be sent to the top of the dependencies. Note that this behaviour is not permanently supported by the plugin and may change in the future.