sortpom Maven Plugin

repository·master·Indexed 18 days ago

https://github.com/ekryd/sortpom

A Maven plugin that automates the sorting and formatting of pom.xml files to maintain readable and standardized XML structures. It provides the 'sort' goal for reordering elements and formatting, and the 'verify' goal to check if elements are unsorted.

Tokens
575
Snippets
3
Records
4
Agent score
13%

What's inside sortpom

  1. What is Sortpom and why use it?

    master

    Sortpom is a Maven plugin designed to sort pom.xml files by formatting the XML and organizing sections into a predefined order.

    Key Benefits:

    • Readability: Standardized formatting makes POM files easier to read.
    • Comparisons: Makes it much easier to compare different module POMs in a project.
    • Consistency: Ensures all modules follow the same structural standards.
  2. Install the Sortpom Maven Plugin

    master

    To use Sortpom, add the sortpom-maven-plugin to your pom.xml build section. It is recommended to configure it to run automatically during the Maven build lifecycle. By default, the plugin creates a backup file so you can review changes made to your pom.xml.

    <build>
      <plugins>
        <plugin>
          <groupId>com.github.ekryd.sortpom</groupId>
          <artifactId>sortpom-maven-plugin</artifactId>
          <version>4.0.0</version>
          <executions>
            <execution>
              <goals>
                <goal>sort</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
        ...
      </plugins>
    </build>
  3. Run a quick test of Sortpom via CLI

    master

    If you want to test the plugin's behavior without modifying your pom.xml file permanently, you can run it directly from the command line using the full plugin coordinates and a predefined sort order.

    mvn com.github.ekryd.sortpom:sortpom-maven-plugin:4.0.0:sort -Dsort.predefinedSortOrder=custom_1
  4. Use Sortpom goals: sort and verify

    master

    The plugin provides two primary goals for managing your pom.xml structure:

    1. sort: Always sorts the current pom.xml file by reordering elements and formatting the XML structure.
    2. verify: Only sorts the pom.xml if the XML elements are currently unsorted. This goal ignores text formatting (like indentation and line breaks) when determining if the file is already sorted.
    mvn sortpom:sort
    # or
    mvn sortpom:verify