Skip to content

[plugin-maven] eclipse formatter sorts Java class members and imports lexicographically rather than alphabetically #2493

Closed

Description

@stechio

Contrary to the formatter within the Eclipse IDE (which sorts Java class members and imports alphabetically), the eclipse formatter within Spotless sorts Java class members and imports lexicographically (!?!) — here it is my configuration:

<eclipse>
  <file>${project.basedir}/config/eclipse/java-style.xml</file>

  <sortMembersEnabled>true</sortMembersEnabled>

  <!-- Optional: Specify the sort order of the member categories. (default: T,SF,SI,SM,F,I,C,M)
    SF,SI,SM,F,I,C,M,T = Static Fields, Static Initializers, Static Methods, Fields, Initializers, Constructors, Methods, (Nested) Types -->
  <sortMembersOrder>T,SF,SI,SM,F,I,C,M</sortMembersOrder>

  <sortMembersVisibilityOrderEnabled>true</sortMembersVisibilityOrderEnabled>

  <!-- Optional: Specify the ordering of members of the same category by the visibility within the category (default: B,V,R,D).
    B,R,D,V = Public, Protected, Package, Private -->
  <sortMembersVisibilityOrder>B,R,D,V</sortMembersVisibilityOrder>
</eclipse>

Feeding Eclipse IDE-formatted source code to spotless-maven-plugin, the resulting source code differs just in its sorting — for example:

  • Eclipse IDE:
public static Optional<StackFrame> callerFrame() {
  . . .
}

public static Object callOrThrow(. . .) {
  . . .
}
  • Spotless:
public static Object callOrThrow(. . .) {
  . . .
}

public static Optional<StackFrame> callerFrame() {
  . . .
}

In case of homonymous methods, lexicographic sorting is applied to the parameter type names:

  • Eclipse IDE:
public static String transform(char[] value) {
  . . .
}

public static String transform(String value) {
  . . .
}
  • Spotless:
public static String transform(String value) {
  . . .
}

public static String transform(char[] value) {
  . . .
}

The imports are also affected by the same problem:

  • Eclipse IDE:
import static org.myexample.util.MyClass.anotherFunction;
import static org.myexample.util.MyClass.NestedType.myFunction;
  • Spotless:
import static org.myexample.util.MyClass.NestedType.myFunction;
import static org.myexample.util.MyClass.anotherFunction;

Why such an inconsistency, considering that both the formatters are based on JDT?
(Have I overlooked any configuration option?)

Activity

  1. changed the title [-][plugin-maven] `eclipse` formatter sorts members lexicographically rather than alphabetically[/-] [+][plugin-maven] `eclipse` formatter sorts Java class members lexicographically rather than alphabetically[/+] on May 28, 2025
  2. changed the title [-][plugin-maven] `eclipse` formatter sorts Java class members lexicographically rather than alphabetically[/-] [+][plugin-maven] `eclipse` formatter sorts Java class members and imports lexicographically rather than alphabetically[/+] on May 28, 2025
  3. aKandzior commented on May 8, 2026

    @aKandzior
    Contributor

    I commited a pull request to fix this issue, see: Use Collator when sorting Eclipse JDT members

  4. stechio commented on May 20, 2026

    @stechio
    Author

    Its release version (3.5.1) worked nicely, thank you @aKandzior!

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions