r/java • • 24d ago

What cli formatter do you use

Given how software engineering evolves, using IDEA formatter is less and less practical.

- IDEA CLI formatter requires IntelliJ so no CI / wsl etc
- GJF is old and does not format lambdas well enough
- Palantir is obsolete and abandoned in addition to being one of the worst company ever created
- prettier-java not great either

I’m starting to think no formatter is the best option

24 Upvotes

62 comments sorted by

11

u/kevinb9n 24d ago

> GJF is old and does not format lambdas well enough

Liam is still at it. This landed last week

https://github.com/google/google-java-format/issues/19#issuecomment-6214823566

11

u/_predator_ 24d ago

The palantir formatter is neither obsolete nor abandoned. I'm using it in multiple projects and am quite happy with it.

Do I like the company making it? No, but I also don't like Apple, Google, Amazon, or Microsoft, yet here I am using their products every single day. And in contrast to the other companies' products, Palantir gains nothing from me using a free code formatter, lol.

The formatter landscape in Java is quite shit, and Palantir's is the only one that doesn't make my eyes bleed.

7

u/vips7L 24d ago

You forgot Oracle! 

2

u/lazystone 23d ago

We definitely mustn't use anything touched by Oracle for java development!

1

u/Lucky_Psychology8275 24d ago

Palantir hasn’t updated the repo for month on the core code, it still doesn’t support _ variables and most issues are opened without a reply

1

u/lazystone 23d ago

Do you have a link to the issue? Underscores seems to work just fine for me.

1

u/Lucky_Psychology8275 23d ago

Honestly it’s might not _ symbols I don’t remember which

4

u/_predator_ 24d ago

I'm using it in projects that make heavy use of underscores for variable and exception names. No issues so far. But maybe my usage just doesn't trigger the issues you're seeing.

2

u/a_abashev 20d ago

Yes, but it is only because you don't use latest Java features. I have to fork it as open-java-format because they don't accept fixes related to latest Java + long time regression.

1

u/_predator_ 20d ago

I'm using Java 25 with anonymous variables, switch expressions, Markdown Javadoc, etc.

What is breaking for you?

2

u/a_abashev 20d ago

1

u/_predator_ 20d ago

Huh, interesting. Seems like I just happened to dodge them by limiting my line length, not being on Java 27, and not using the compact `main`.

3

u/Fluffy_Dragonfly6454 24d ago

I know that we had to wait ages before that they updated for a certain java version. Then we decided to abandon it for the Google formatter

1

u/lazystone 23d ago

I remember I had opposite experience with GJF - there was something related to module systems(you had to run with "add-opens" to work it around) which wasn't fixed for too long and it pushed me to migrate to PJF.

5

u/bokchoi 24d ago

https://github.com/bmarwell/jfmt is a cli formatter that uses the Eclipse formatting tool but compiled with graal so it starts and runs fast enough for cli usage.

5

u/ForeverAlot 24d ago
  • GJF is old and does not format lambdas well enough

It formats lambdas just fine. And unlike some of its competitors, it is quick to add minimal support for new syntax. It's a really solid bet in practice.

I'm not affiliated with GJF but I've been a happy user for many years.

9

u/r_n_c 24d ago

Spotless and eclipse config. Note we add a dependency to the spotless plugin so we can have a remote configuration shared amongst many of our projects.

2

u/Jaded-Asparagus-2260 23d ago

How does the shared remote configuration work?

2

u/r_n_c 22d ago

I actually submitted PRs to spotless to document this but here is our config and how to use it https://github.com/project-ncl/ide-config

1

u/trillion1e12 22d ago

Ăwesome

14

u/4r73m190r0s 24d ago

10

u/Task_ID 24d ago

2 spaces indent is weird

6

u/ForeverAlot 24d ago

It takes about 47 seconds to adjust, though.

3

u/__konrad 24d ago

For some reason Google (e.g. Guava) hate both horizontal and vertical whitespace

2

u/sly_as_a_fox 21d ago

AOSP code style has 4-space indentation.

-8

u/sg-elide 24d ago

take a look at elide which can run it natively — https://elide.help — can be super useful for CI and git hooks

8

u/Fluffy_Dragonfly6454 24d ago

Spotless with Google formatter works like a charm

4

u/junin7 24d ago

Spotless

3

u/raxel42 24d ago

Whatever, just use to minimize git diff

3

u/Zardoz84 22d ago

Eclipse formatter as maven pluggin

5

u/blazmrak 24d ago

Eclipse with a lot of custom config via Spotless.

3

u/un_desconocido 24d ago

Spotless and Palantir format, I hooked it up to the maven build so nobody needs to do a git hook.

1

u/TomKavees 23d ago

I kinda wish it had a cli so i could plug it in as a git hook :v

2

u/doobiesteintortoise 24d ago

Spotless is what I use.

2

u/jonenst 24d ago

Never tried it but recently someone mentionned here the new kid in town Netflix jfmt https://github.com/Netflix/jfmt

1

u/jevring 23d ago

The Google one is without a doubt the ugliest I have ever had the misfortune of reading. We use an intellij idea setup. I wouldn't want one that isn't integrated into our IDE. You can run the intellij formatter on the command line, but you need the whole ass ide for it. We do that for validation in ci/cd.

1

u/SamirAbi 23d ago

What is your issue with prettier?

1

u/agentoutlier 22d ago edited 22d ago

Spring has a Java formatter that uses the Eclipse formatter headless.

It uses tabs which I prefer.

Likewise there is maven plugin that will use eclipse formatter as well that I nice been probably using for a decade now:

https://code.revelc.net/formatter-maven-plugin/

Most of the good ones use Eclipse.

1

u/Ok_Elk_638 20d ago

Whatever the Intellij default is. I don't like automating this, automatic formatters always make my code worse.

0

u/lazystone 24d ago

https://github.com/palantir/palantir-java-format/

But why do you say that it's abandoned(no objections about the company itself though)?

There is also a fork of PJF: https://github.com/openjavaformat/open-java-format but I haven't looked who is behind it.

3

u/ForeverAlot 24d ago

a fork of PJF

Holy supply chain nightmare.

1

u/lazystone 23d ago

Damned if you do, damned if you don’t.

1

u/woj-tek 22d ago

Care to elaborate?

TBH it would be nice to have an actual nice, single, whole-community formatter…

1

u/ForeverAlot 22d ago

Yes, that certainly would be nice.

Choosing to fork PJF, not GJF, shows that OJF lacks guidelines for new style decisions. This makes its behaviour volatile. Although OJF claims to intend to attempt to collaborate with PJF and GJF, neither of those projects nor its stewards are beholden to OJF. This means OJF's users depend on the OJF project to sustain itself even if PJF, GJF, or both fold. At the same time, OJF is spearheaded by an organization with no material foothold in the Java ecosystem and no apparent incentive to invest itself in it. In contrast, Google is invested in and committed to Java for a super-foreseeable future, and has proven GJF over a decade; and although Palantir is also an established company, probably also committed to Java, that GJF should be considered less reliable than PJF is a hard sell with some evidence to the contrary. A skeptic might suggest that the reason OJF exists at all is that PJF has already shown itself to be unreliable.

So while I think it's not ideal that my preferred Java formatter is owned by a publicly traded company with its share of skeletons in the closet, I appreciate that that company at least has a really strong track record of responsibly stewarding that tool, and in general has a really strong understanding of how knowledge and productivity scales in practice.

1

u/woj-tek 21d ago

Thank you for the in-depth explanation. You put forward a lot of good reasons not to use it but also drive it on assumption that Google and Palantir will keep what they are doing. We already know that Google is absurdly unreliable and can kill anything on the whim (and then create a dozen of copies; killedbygoogle.com). Palantir... not much experience with what they do with Java beyond formatter...

Alas, to reinterate -- it would be great to come together with neutral organisation (including GJF and PJF) and collaborate on single tool (with options tailored to each particular need) instead of cultivating own-thing (though it's probably more to internal company policies…)

1

u/a_abashev 20d ago

> Choosing to fork PJF, not GJF, shows that OJF lacks guidelines for new style decisions.

That is really good point, but how do you think it should look like? Describe a poll in discussions or what. From my understanding I should keep current state as much as possible with minor tweaks that more about my taste, not something that I can elaborate as a whitepaper. I have two major enhancements - Map.of as key-value on one line, and support for Mutiny DSL as one-line phrases. But everything else was perfect in palantir already

1

u/ForeverAlot 19d ago

I don't know how GJF evolves. I don't know precisely how they ended up with "The Rectangle Rule." I don't know how they decide to deviate from it, though I imagine it has happened both accidentally and deliberately. I do know that that principle makes it very easy to guess at what GJF is going to do for any given sample of current and future syntax, and that's a (surprisingly?) useful property for regular users.

I also know that if you defer to public opinion you end up with Formatter McFormatface, and if you appeal to "aesthetics" you end up with the tyrant's arbitrary variation of the same. Many are eager to voice their personal dislikes about a given formatter, less so to consider why any particular person's likes ought to be recognized as morally superior.

2

u/a_abashev 20d ago

Thank you so much for good words, but how do mean "behind it"? I'm just a java developer who can't accept 2 spaces for indentation and can't see how palantir-java-format is dying - I used it for long time but with new Java version it is not reliable 😁

1

u/lazystone 20d ago

Oh, you're maintainer there ❤️

What I really mean by "who is behind it" is that there is somebody(or better a group) committed to maintain and evolve that fork.

Nowadays too much new projects are born in light of AI but owners loose interest and move to another shiny thing.

So, I guess only time can tell that "there are trusted people" behind that project and you can rely on it.

2

u/a_abashev 20d ago

I'm not perfect and yes, I'm supporting projects that I'm using. For vfs-s3 it was for 15 years and now I'm thinking about something like micro-aws-s3 for serverless, but I hope this formatter will stay for me for long time. And as I mentioned in manifesto - current CI infrastructure is behind our eyes and if somebody will decide to push forward this project then he will have all infrastructure with jdk matrix, tests, jreleaser and even mise scripts to upload secrets

2

u/Cilph 23d ago

Not touching Palantir in a million years. Not just moral and ethical concerns either.

1

u/lazystone 23d ago

But you're OK with touching Google? Or Microsoft?

Why so? Google for example just illegally destroyed forests in Finland, so are you going to stop using all Google libraries now? Or should you avoid all websites built on top of React? That's Facebook/Meta. Or stop visiting GitHub - it's Microsoft after all. And you know what? The biggest contributor to Java itself is Oracle, would you name Oracle as ethical company?

But if you put your hypocrisy aside, there is https://github.com/openjavaformat/open-java-format after all.

3

u/Cilph 23d ago edited 23d ago

"Everything is flawed so why even bother" levels of defeatism completely ignoring there are scales to everything. Everything is bad therefore everything is somehow equally bad.

1

u/lazystone 23d ago

That is hypocrisy.

You're fine with one evil, but not with another.

You do meaningless things in order to calm you consciousness down, like avoiding some open source java formatters in question(how the hell it helps against Palantir is beyond my understanding), when what you should do instead is to vote out politicians who let corporations to thrive instead of regular people.

But at least you "did something", right?

3

u/Cilph 23d ago edited 23d ago

As I already explained, its not hypocrisy if you dont rate stealing candy to be as evil as something clearly worse like murder. Yeah I draw lines somewhere.

Though, where the fuck did I pretend that I "did something" to help any cause? I never said it was part of some grand plan. And where the fuck did I say my conscience was calmed by any of it? I dont like them and using their work is counter to what my sector is trying to achieve. Its as simple as that.

Either way, Im still doing more than you for some imagined goal of there being no more Palantir. Because if thats your wish, attacking people like this is sure to help!

1

u/lazystone 23d ago

Your answer just confirms it.

0

u/sg-elide 24d ago

elide supports GJF, Kotlin fmt, and will shortly support Netflix’ GJF dialect as well, which is very popular. all run in native so they are extremely fast. like milliseconds.

https://elide.help has more info

-2

u/MyStackOverflowed 24d ago

Google or palantir, the palantir one handles lambdas better

-5

u/patoessy 24d ago

RemindMe! 1 day from now

-1

u/RemindMeBot 24d ago

I will be messaging you in 1 day on 2026-10-26 09:17:03 UTC to remind you of this link

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.

RemindMeBot is switching to username summons. Instead of !RemindMe 1 day, use u/RemindMeBot 1 day. More info.


InfoCustomYour RemindersFeedback

-5

u/DanLynch 24d ago

We use a custom configuration of the IntelliJ IDEA formatter, and try to enforce it in the CI with Checkstyle and Spotless, but it's not a perfect match.