You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've converted GJF to a compile-only integration. To reduce complexity, I would suggest that we'll require GJF of at least version 1.8 (which was released back in May 2020). Before that, we would have two API changes that would require to have specific compile-only variants. Since that version is years old, I don't think any spotless user would have an issue with that requirement.
After having converted GJF to a compile-only dependency, I've tried to introduce a configuration for the max-line-length. GJF however has taken every measure, for this property to not be changeable, as can be seen here:
They've decided to make this a public static final int that gets assigned on declaration. So even with (ugly) reflection, the value cannot be changed, since the compiler does inline this value wherever it is used within the gjf lib.
It was possible to change this value up to GJF Release 1.7 by doing some ugly wrapping of the JavaFormatterOptions class at this location:
This approach, however, is no longer feasible, as it is only working for GJF Versions ≤ 1.7.
TL;DR: it is not possible to make GFJ's max-line-length property configurable. Which means this feature request cannot be satisfied.
@nedtwigg Given the above, should I create a PR to merge the transition of GJF to a compile-only dependency, or would you rather keep it "the old way" using reflection?
@simschla I just wanted to say how bloomin' impressed I am by the time and effort you've spent investigating all this and writing it down, so well done!! 👏
I'll leave it to @nedtwigg to decide if the compile-only dependency work is worth merging in.
The blocker that closed this issue no longer exists.
google-java-formatv1.37.0 (released 2026-10-01) ships a native --max-line-length flag — this is google/google-java-format#425, landed in 6b86849.
Specifically, the public static final int Formatter.MAX_LINE_LENGTH constant that @simschla identified as the hard blocker above (inlined at compile time, immune even to reflection) is gone. The column limit now flows through the options object — Formatter calls options.maxLineLength() — and the new public builder makes it fully programmatic:
// JavaFormatterOptions.Style is now a record with a public builderJavaFormatterOptions.Style.builder()
.aosp() // or .google()
.maxLineLength(120)
.build();
So Spotless could now expose something like <maxLineLength>120</maxLineLength> on the googleJavaFormat step (Gradle: googleJavaFormat { maxLineLength(120) }), gated on gjf 1.37.0+. For what it's worth, Google describes the new flag as an orthogonal option — it moves the column limit without changing any other layout decisions, so it doesn't conflict with the "opinionated, minimal configuration" philosophy.
The default-version bump to 1.37.0 is also pending in #3130. @simschla
Activity
[-]No max line length for google formatter[/-][+]Set max line length for google formatter[/+]nedtwigg commentedon Feb 8, 2023
If
gjfwas converted to a compile-only integration, as inThen this would be pretty easy to implement. PRs welcome.
simschla commentedon Mar 9, 2023
I've converted GJF to a compile-only integration. To reduce complexity, I would suggest that we'll require GJF of at least version
1.8(which was released back in May 2020). Before that, we would have two API changes that would require to have specific compile-only variants. Since that version is years old, I don't think any spotless user would have an issue with that requirement.After having converted GJF to a compile-only dependency, I've tried to introduce a configuration for the max-line-length. GJF however has taken every measure, for this property to not be changeable, as can be seen here:
https://github.com/google/google-java-format/blob/1a0065696b4f408313dbd24f9d6606d758e98868/core/src/main/java/com/google/googlejavaformat/java/Formatter.java#L89
They've decided to make this a
public static final intthat gets assigned on declaration. So even with (ugly) reflection, the value cannot be changed, since the compiler does inline this value wherever it is used within the gjf lib.It was possible to change this value up to GJF Release
1.7by doing some ugly wrapping of theJavaFormatterOptionsclass at this location:https://github.com/google/google-java-format/blob/69e2efccf9938cfb08b1d5315ad61ca4484bbd0a/core/src/main/java/com/google/googlejavaformat/java/JavaFormatterOptions.java#L60-L64
This is, ultimately, what the aformentioned maven-plugin does:
https://github.com/talios/googleformatter-maven-plugin/blob/2034133fe14f0ee928c6942cd037f1fbd52f0abd/src/main/java/com/theoryinpractise/googleformatter/GoogleFormatterMojo.java#L142-L146
This approach, however, is no longer feasible, as it is only working for GJF Versions ≤
1.7.TL;DR: it is not possible to make GFJ's
max-line-lengthproperty configurable. Which means this feature request cannot be satisfied.@nedtwigg Given the above, should I create a PR to merge the transition of GJF to a compile-only dependency, or would you rather keep it "the old way" using reflection?
jbduncan commentedon Mar 9, 2023
@simschla I just wanted to say how bloomin' impressed I am by the time and effort you've spent investigating all this and writing it down, so well done!! 👏
I'll leave it to @nedtwigg to decide if the compile-only dependency work is worth merging in.
nedtwigg commentedon Mar 10, 2023
A GJF conversion to compile-only which drops support for pre-1.8 is very welcome, thanks @simschla!
I apologize for sending a wild goose-chase regarding max-line-length. I'm going to close this issue since it appears impossible to implement.
simschla commentedon Mar 17, 2023
No worries, as it turns out, there is always something to be learned, even if the result is finding out, that something is not possible... 🤔
I've created #1630 to convert gjf to a compile-only dependency.
pks-1981 commentedon Oct 3, 2023
Hello
How configure it on maven?
???
simschla commentedon Oct 3, 2023
@pks-1981 As of now, this setting is not possible due to design decisions on Google's side.
xzxiaoshan commentedon Oct 23, 2026
The blocker that closed this issue no longer exists.
google-java-formatv1.37.0 (released 2026-10-01) ships a native--max-line-lengthflag — this is google/google-java-format#425, landed in 6b86849.Specifically, the
public static final int Formatter.MAX_LINE_LENGTHconstant that @simschla identified as the hard blocker above (inlined at compile time, immune even to reflection) is gone. The column limit now flows through the options object —Formattercallsoptions.maxLineLength()— and the new public builder makes it fully programmatic:So Spotless could now expose something like
<maxLineLength>120</maxLineLength>on thegoogleJavaFormatstep (Gradle:googleJavaFormat { maxLineLength(120) }), gated on gjf1.37.0+. For what it's worth, Google describes the new flag as an orthogonal option — it moves the column limit without changing any other layout decisions, so it doesn't conflict with the "opinionated, minimal configuration" philosophy.The default-version bump to 1.37.0 is also pending in #3130.
@simschla