Skip to content

[Proposal] Standardize Maven POM formatting with Spotless SortPom #5701

Closed

Description

@shalk

Is your feature request related to a problem? Please describe.

Apollo already uses spotless-maven-plugin for Java formatting, and the code-style CI workflow runs mvn spotless:check. However, the current Spotless configuration does not include Maven POM formatting.

The root and module pom.xml files have inconsistent formatting, including a mixture of tabs and spaces, different attribute wrapping, and inconsistent placement of POM elements. For example, the root POM mostly uses tabs while the Spotless configuration uses spaces.

As a result, POM formatting is not checked by the existing code-style workflow, and contributors using different IDE settings can introduce unrelated formatting changes. This creates avoidable diff noise and review work.

This is a focused follow-up to #5480, extending the existing formatting tooling to Maven POM files rather than introducing another standalone formatter.

Describe the solution you would like

Add the following POM formatter configuration alongside the existing <java> section in the root POM's Spotless plugin configuration:

<pom>
  <includes>
    <include>pom.xml</include>
  </includes>
  <sortPom>
    <expandEmptyElements>false</expandEmptyElements>
  </sortPom>
</pom>

The inherited configuration would format each module's own pom.xml when Spotless runs across the Maven reactor.

Expected formatting policy

  • Use SortPom's default recommended_2008_06 profile to standardize POM element order, including the fields inside individual dependencies and plugins.
  • Use UTF-8 and two-space indentation.
  • Keep empty elements self-closing, for example <removeUnusedImports/>.
  • Do not enable sorting dependency lists, plugin lists, properties, modules, or plugin executions. Keep their existing relative order to avoid introducing unnecessary or potentially order-sensitive changes.
  • Keep the existing Java formatter and its Eclipse style configuration unchanged. Limit this change to Maven POM files, not arbitrary XML resources.

Implementation and validation outline

  1. Add the POM formatter configuration to the existing Spotless plugin.
  2. Run mvn spotless:apply to establish a consistent baseline for the root and module POM files in a dedicated formatting change, without dependency upgrades or unrelated functional changes.
  3. Review the resulting diff to ensure it consists of formatting, supported POM element reordering, and the formatter configuration itself.
  4. Run mvn spotless:check, apply formatting a second time to verify idempotence, and run mvn clean test to check for build regressions.
  5. Clarify in CONTRIBUTING.md that the existing Spotless commands also format/check POM files. The existing CI command should then cover POM formatting without a separate workflow.

Describe alternatives you have considered

  • IDE-only formatting: does not provide a shared, CI-enforced result and may vary across contributors' IDE settings.
  • A standalone SortPom Maven plugin: would introduce another command/configuration when Spotless already integrates SortPom.
  • Whitespace-only formatting: could normalize indentation but would not standardize the placement of POM elements.

Additional context

I have a local draft adding this configuration and normalizing the root and module POM files. Build/test validation is still to be completed before submitting a PR.

The relevant formatting choices are compatible with the Google XML Style Guide: it allows two-space indentation and both self-closing and explicit empty-element forms, and does not prescribe a universal Maven POM element order or a fixed line-length limit.

The Eclipse style file in apollo-buildtools/style configures Java formatting only. The IntelliJ template also contains XML settings, so IDE wrapping/rearrangement can differ from SortPom. Spotless should be the authoritative POM formatter; aligning IDE XML settings can be considered separately to avoid broadening this change.

Activity

  1. github-actions commented on Oct 23, 2026

    @github-actions

    Thanks for opening this feature request! The proposal to standardize Maven POM formatting via Spotless SortPom is well-structured and clearly motivated.

    This is a great follow-up to #5480, and I appreciate the detailed implementation outline including:

    • The specific SortPom configuration and formatting policy
    • Clear validation steps (spotless:check, idempotence verification, test suite)
    • Documentation updates for CONTRIBUTING.md

    The issue includes all necessary context: problem statement, proposed solution, alternatives considered, and local validation status. Maintainers can proceed with review whenever your draft PR is ready.

    A few notes for implementation:

    1. Ensure the spotless:apply changes in the dedicated formatting commit include only POM formatting and configuration—no functional or dependency changes.
    2. Confirm that the inherited Spotless configuration correctly applies across module POMs during the reactor build.
    3. Update CI documentation if needed to clarify that the existing spotless workflow now covers both Java and POM files.

    AI generated by Apollo Issue Triage

  2. added a commit that references this issue on Oct 24, 2026
    7b282b4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestCategorizes issue as related to a new feature.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions