Repository navigation
Keep Style.PALANTIR as a @Deprecated alias for Style.OJF - #200
Conversation
openjavaformat/open-java-format#200 keeps Style.PALANTIR as a deprecated alias of Style.OJF that formats the same, so code that names it, or looks the style up by name, keeps working after the change of coordinates. Migrate now says so, and that up to 21.0.1 such code does not compile, or fails with NoSuchFieldError when it was built against palantir-java-format. To merge with the release that has the alias: until then the page would promise what the published formatter does not do.
|
Thank you! |
|
I've filed: diffplug/spotless#3179 |
|
@glaforge thank you so much! I didn't know about your challenge, but my evening mood for making PRs came at the right time 😁 One amendment to your comparison table: we have only two options, OJF or PALANTIR, because we are not able to support the Google style at the same time. If you have a similar usage profile, there are some interesting things in addition to JBang (my favourite, and it brought a lot of energy into this fork): The Palantir Gradle plugin is nice, but it doesn't support the configuration cache or the build cache. In my understanding, that is a must-have for Java development right now. open-java-format has both, and it also fixes an issue with multi-module projects and a single shared repository for the formatter. MAX_ROUNDS comes from this regression: palantir#1632, so a more detailed comparison will show a difference in our numbers 😉 And under 'recent Java features' you forgot about JDK 28 and For the Spotless fix I'll add as many reactions as I can, but you need somebody on the other side. There is also one important thing: Spotless uses this call from |
Summary
Restores
JavaFormatterOptions.Style.PALANTIRas a@Deprecatedalias forStyle.OJF(indentationMultiplier = 2,maxLineLength = 120) inopen-java-format-spiand treatsStyle.PALANTIRidentically toStyle.OJFinImportOrderer.Motivation: Ecosystem & Spotless Backward Compatibility
As noted in the README ("Identical Java packages.
com.palantir.javaformat.*stays, so your code and the SPI keep working. One-line migration. Change the coordinates below. Nothing else."), keeping binary and reflective compatibility incom.palantir.javaformat.java.JavaFormatterOptions.Styleallows existing integrations to swap coordinates without breaking:palantirJavaFormat()step (com.diffplug.spotless.java.PalantirJavaFormatStep):Spotless's built-in step defaults to
DEFAULT_STYLE = "PALANTIR"and invokescom.palantir.javaformat.java.JavaFormatterOptions$Style.valueOf(style)via reflection. When a Gradle or Maven project overrides the dependency of Spotless'spalantirJavaFormat()step todev.openjavaformat:open-java-formatwithout explicitly passing.style("OJF"),Style.valueOf("PALANTIR")previously threw:@Deprecated PALANTIR(2, 120)present onStyle, existing SpotlesspalantirJavaFormat()configurations and direct Java API/SPI callers usingStyle.PALANTIRwork out of the box as a true one-line coordinate swap.Codebases calling
JavaFormatterOptions.builder().style(Style.PALANTIR).build()orImportOrderer.reorderImports(input, Style.PALANTIR)continue to compile and format identically toStyle.OJF, while receiving a standard Java deprecation warning guiding them towardStyle.OJF.(Note: CLI style flag handling from
e8c0ee19is intentionally left untouched so--palantiron the CLI continues to fail fast with exit code 2 as tested inMainTest.unknownFlagIsAnError.)Suggested Follow-up Contribution to
diffplug/spotlessIn addition to keeping
Style.PALANTIRas a deprecated alias here for immediate backward compatibility, a natural follow-up contribution todiffplug/spotlesswould giveopen-java-formatfirst-class support in Spotless for both Gradle and Maven users:spotless-lib(com.diffplug.spotless.java.OpenJavaFormatStep):dev.openjavaformat:open-java-format(default version"21.0.1"or latest21.x)"OJF"(supporting"OJF","PALANTIR","GOOGLE","AOSP") andformatJavadoc(boolean)FormatterService+JavaFormatterOptionsreflective invocation mechanism asPalantirJavaFormatStep(since thecom.palantir.javaformat.java.*package names are preserved).spotless-plugin-gradle(com.diffplug.gradle.spotless.JavaExtension):openJavaFormat()andopenJavaFormat(String version)DSL methods onspotless { java { ... } }with.style(String)and.formatJavadoc(boolean)configuration methods.spotless-plugin-maven(com.diffplug.spotless.maven.java.OpenJavaFormat):<openJavaFormat>in<configuration><java>...</java></configuration>with optional<version>,<style>, and<formatJavadoc>parameters.Verification
FormatterTest.palantirStyleAliasMatchesOjfStyleverifyingStyle.valueOf("PALANTIR"),indentationMultiplier(),maxLineLength(),Formatter.formatSource,Formatter.formatSourceAndFixImports, andImportOrderer.reorderImports../gradlew formatDiff :open-java-format-spi:check :open-java-format:check :open-java-format:test.