Skip to content

Expose maxLineLength on the googleJavaFormat step (configurable upstream since gjf 1.37.0) #3151

Open

Description

@xzxiaoshan

Summary

The googleJavaFormat step currently has no way to configure the column limit, and historically there was no way to add one: upstream hard-coded 100 columns in Formatter.MAX_LINE_LENGTH, a public static final constant that got inlined at compile time — which is why #1563 was closed back in 2023 as impossible to implement.

That upstream blocker is now gone. google-java-format v1.37.0 (released 2026-10-01) added an official --max-line-length flag, resolving google/google-java-format#425 (open since Dec 2019). The gjf maintainers describe it as an orthogonal option — it moves the column limit without changing any other layout decisions — so exposing it doesn't conflict with the "opinionated, minimal configuration" philosophy.

What the new API looks like

The hard-coded constant was removed; the limit now flows through the options object. JavaFormatterOptions.Style is now a record with a public builder that Spotless can call directly (the step already builds a JavaFormatterOptions for the existing style / reflowLongStrings / formatJavadoc settings):

JavaFormatterOptions.Style.builder()
    .aosp()              // or .google()
    .maxLineLength(120)
    .build();

(landed in 6b86849)

Requested

Expose the option on the step, gated on gjf 1.37.0+:

Gradle:

googleJavaFormat {
    maxLineLength(120)
}

Maven:

<googleJavaFormat>
    <version>1.37.0</version>
    <maxLineLength>120</maxLineLength>
</googleJavaFormat>

Considerations

  • gjf 1.29+ requires JDK 21+ to run. Spotless already applies JVM-tiered defaults for gjf (1.28.0 on JVM 17, newer on 21+), so this option would effectively require the JVM-21 tier with an explicit gjf version of 1.37.0 or newer.
  • The default-version bump to 1.37.0 is currently pending in Update dependency com.google.googlejavaformat:google-java-format to v1.37.0 #3130.
  • 1.37.0 also added --style=google|aosp, and useTabs / indentationMultiplier became programmatically settable on the same builder — potential follow-ups, not part of this request.

Activity

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