{"id":20208864,"url":"https://github.com/palantir/palantir-java-format","last_synced_at":"2026-01-19T12:02:14.176Z","repository":{"id":37548854,"uuid":"214273098","full_name":"palantir/palantir-java-format","owner":"palantir","description":"A modern, lambda-friendly, 120 character Java formatter.","archived":false,"fork":false,"pushed_at":"2025-05-13T08:48:34.000Z","size":4592,"stargazers_count":565,"open_issues_count":111,"forks_count":55,"subscribers_count":265,"default_branch":"develop","last_synced_at":"2025-05-13T09:40:52.062Z","etag":null,"topics":["codeformatter","formatter","gofmt","java","octo-correct-managed"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/palantir.png","metadata":{"files":{"readme":"README.md","changelog":"changelog/0.0.1/pr-2.v2.yml","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-10-10T19:53:18.000Z","updated_at":"2025-05-13T02:26:52.000Z","dependencies_parsed_at":"2023-09-23T04:47:13.124Z","dependency_job_id":"f00ea32e-6923-47de-a7b4-34ee954e6de3","html_url":"https://github.com/palantir/palantir-java-format","commit_stats":null,"previous_names":[],"tags_count":113,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palantir%2Fpalantir-java-format","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palantir%2Fpalantir-java-format/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palantir%2Fpalantir-java-format/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palantir%2Fpalantir-java-format/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/palantir","download_url":"https://codeload.github.com/palantir/palantir-java-format/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254227613,"owners_count":22035670,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codeformatter","formatter","gofmt","java","octo-correct-managed"],"created_at":"2024-11-14T05:37:38.193Z","updated_at":"2026-01-16T23:57:04.597Z","avatar_url":"https://github.com/palantir.png","language":"Java","readme":"\u003cp align=\"center\"\u003e\n\u003ca href=\"https://central.sonatype.com/search?q=com.palantir.javaformat\"\u003e\u003cimg src=\"https://img.shields.io/maven-central/v/com.palantir.javaformat/palantir-java-format\" alt=\"Maven Central\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://plugins.gradle.org/plugin/com.palantir.java-format\"\u003e\u003cimg src=\"https://img.shields.io/gradle-plugin-portal/v/com.palantir.java-format\" alt=\"Gradle Plugin Portal\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://plugins.jetbrains.com/plugin/13180-palantir-java-format\"\u003e\u003cimg src=\"https://img.shields.io/jetbrains/plugin/v/13180\" alt=\"Jetbrains Plugin\"/\u003e\u003c/a\u003e\n\u003ca href=\"LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/palantir/palantir-java-format\" alt=\"License\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://autorelease.general.dmz.palantir.tech/palantir/palantir-java-format\"\u003e\u003cimg src=\"https://img.shields.io/badge/Perform%20an-Autorelease-success.svg\" alt=\"Autorelease\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n# Palantir Java Format\n\n_A modern, lambda-friendly, 120 character Java formatter._\n\n- [Eclipse plugin](https://github.com/palantir/palantir-java-format/tree/develop/eclipse_plugin)\n- [IntelliJ plugin](https://plugins.jetbrains.com/plugin/13180-palantir-java-format)\n- [Gradle plugin](#palantir-java-format-gradle-plugin)\n- [Spotless](#spotless)\n\nIt is based on the excellent [google-java-format](https://github.com/google/google-java-format), and benefits from the work of all the [original authors](https://github.com/google/google-java-format/graphs/contributors). palantir-java-format is available under the same [Apache 2.0 License](./LICENSE).\n\n## Upsides of automatic formatting\n\n- reduce 'nit' comments in code reviews, allowing engineers to focus on the important logic rather than bikeshedding about whitespace\n- bot-authored code changes can be auto-formatted to a highly readable style (we use [refaster](https://errorprone.info/docs/refaster) and [error-prone](https://errorprone.info/docs/patching) heavily)\n- increased consistency across all repos, so contributing to other projects feels familiar\n- reduce the number builds that trivially fail checkstyle\n- easier to onboard new devs\n\n## Downsides of automatic formatting\n\n- if you don't like how the formatter laid out your code, you may need to introduce new functions/variables\n- the formatter is not as clever as humans are, so it can sometimes produce less readable code (we want to fix this where feasible)\n\nMany other languages have already adopted formatters enthusiastically, including typescript (prettier), go (gofmt), rust (rustfmt).\n\n## Motivation \u0026 examples\n\n(1) google-java-format output:\n\n```java\nprivate static void configureResolvedVersionsWithVersionMapping(Project project) {\n    project.getPluginManager()\n            .withPlugin(\n                    \"maven-publish\",\n                    plugin -\u003e {\n                        project.getExtensions()\n                                .getByType(PublishingExtension.class)\n                                .getPublications()\n                                .withType(MavenPublication.class)\n                                .configureEach(\n                                        publication -\u003e\n                                                publication.versionMapping(\n                                                        mapping -\u003e {\n                                                            mapping.allVariants(\n                                                                    VariantVersionMappingStrategy\n                                                                            ::fromResolutionResult);\n                                                        }));\n                    });\n}\n```\n\n(1) palantir-java-format output:\n\n```java\nprivate static void configureResolvedVersionsWithVersionMapping(Project project) {\n    project.getPluginManager().withPlugin(\"maven-publish\", plugin -\u003e {\n        project.getExtensions()\n                .getByType(PublishingExtension.class)\n                .getPublications()\n                .withType(MavenPublication.class)\n                .configureEach(publication -\u003e publication.versionMapping(mapping -\u003e {\n                    mapping.allVariants(VariantVersionMappingStrategy::fromResolutionResult);\n                }));\n    });\n}\n```\n\n(2) google-java-format output:\n\n```java\nprivate static GradleException notFound(\n        String group, String name, Configuration configuration) {\n    String actual =\n            configuration.getIncoming().getResolutionResult().getAllComponents().stream()\n                    .map(ResolvedComponentResult::getModuleVersion)\n                    .map(\n                            mvi -\u003e\n                                    String.format(\n                                            \"\\t- %s:%s:%s\",\n                                            mvi.getGroup(), mvi.getName(), mvi.getVersion()))\n                    .collect(Collectors.joining(\"\\n\"));\n    // ...\n}\n```\n\n(2) palantir-java-format output:\n\n```java\nprivate static GradleException notFound(String group, String name, Configuration configuration) {\n    String actual = configuration.getIncoming().getResolutionResult().getAllComponents().stream()\n            .map(ResolvedComponentResult::getModuleVersion)\n            .map(mvi -\u003e String.format(\"\\t- %s:%s:%s\", mvi.getGroup(), mvi.getName(), mvi.getVersion()))\n            .collect(Collectors.joining(\"\\n\"));\n    // ...\n}\n```\n\n## Optimised for code review\n\nEven though PJF sometimes inlines code more than other formatters, reducing what we see as unnecessary breaks that don't help code comprehension, there are also cases where it will split code into more lines too, in order to improve clarity and code reviewability.\n\nOne such case is long method chains. Whereas other formatters are content to completely one-line a long method call chain if it fits, it doesn't usually produce a very readable result:\n\n```java\nvar foo = SomeType.builder().thing1(thing1).thing2(thing2).thing3(thing3).build();\n```\n\nTo avoid this edge case, we employ a limit of 80 chars for chained method calls, such that _the last method call dot_ must come before that column, or else the chain is not inlined.\n\n```java\nvar foo = SomeType.builder()\n        .thing1(thing1)\n        .thing2(thing2)\n        .thing3(thing3)\n        .build();\n```\n\n## Palantir Java format Gradle plugin\n\nYou should apply this plugin to all projects where you want your java code formatted, e.g.\n\n```groovy\nbuildscript {\n    dependencies {\n        classpath 'com.palantir.javaformat:gradle-palantir-java-format:\u003cversion\u003e'\n    }\n}\nallprojects {\n    apply plugin: 'com.palantir.java-format'\n}\n```\n\nApplying this automatically configures IntelliJ, whether you run `./gradlew idea`\nor import the project directly from IntelliJ, to use the correct version of the formatter\nwhen formatting java code.\n\n`./gradlew format` can be enabled by using the [com.palantir.baseline-format](https://github.com/palantir/gradle-baseline#compalantirbaseline-format) Gradle plugin.\n\n## Spotless\n\n- See [integration in Spotless Gradle plugin](https://github.com/diffplug/spotless/tree/main/plugin-gradle#palantir-java-format).\n- See [integration in Spotless Maven plugin](https://github.com/diffplug/spotless/tree/main/plugin-maven#palantir-java-format).\n\n## IntelliJ plugin\n\nA\n[palantir-java-format IntelliJ plugin](https://plugins.jetbrains.com/plugin/13180)\nis available from the plugin repository. To install it, go to your IDE's\nsettings and select the `Plugins` category. Click the `Marketplace` tab, search\nfor the `palantir-java-format` plugin, and click the `Install` button.\n\nThe plugin will be disabled by default on new projects, but as mentioned [above](#compalantirjava-format-gradle-plugin), \nif using the `com.palantir.java-format` gradle plugin, it will be recommended \nin IntelliJ, and automatically configured.\n\nTo manually enable it in the current project, go\nto `File→Settings...→palantir-java-format Settings` (or `IntelliJ\nIDEA→Preferences...→Other Settings→palantir-java-format Settings` on macOS) and\ncheck the `Enable palantir-java-format` checkbox.\n\nTo enable it by default in new projects, use `File→Other Settings→Default\nSettings...`.\n\nWhen enabled, it will replace the normal `Reformat Code` action, which can be\ntriggered from the `Code` menu or with the Ctrl-Alt-L (by default) keyboard\nshortcut.\n\n### Running a pre-release version of the IntelliJ plugin\n\n1. Clone this repo\n2. run `./gradlew :idea-plugin:build`\n3. In IntelliJ, install a plugin from disk. Build artifacts are located in `./idea-plugin/build/distributions/`\n\n![Install plugin from disk](./docs/images/install_plugin_from_disk.png)\n\n## Java 21 Support\n\nIn [1211](https://github.com/palantir/palantir-java-format/pull/1211) we shipped Java 21 support. In order to use the \nJava 21 formatting capabilities, ensure that either: \n\n- the Gradle daemon and the Intellij Project SDK are set to Java 21\n- or that the gradle property `palantir.native.formatter=true`. This will run the formatter as a native image, \n- independent of the Gradle daemon/Intellij project JDK version. \n\n### Native image formatter\n\n[This comment](https://github.com/palantir/palantir-java-format/issues/952#issuecomment-2575750610) explains why we \nswitched to a native image for the formatter. The startup time for the native image esp. in Intellij is \u003e10x faster than\nspinning up a new JVM process that does the formatting.\nHowever, the throughput of running the native image for a large set of files (eg. running `./gradlew spotlessApply`) is \nconsiderably slower (eg. 30s using the Java implementation vs 1m20s using the native image implementation). Therefore,\nwhen running the formatter from `spotlessApply` we will default to using the Java implementation (if the Java version \u003e= 21).\n\n\n## Future works\n\n- [ ] preserve [NON-NLS markers][] - these are comments that are used when implementing NLS internationalisation, and need to stay on the same line with the strings they come after.\n\n[NON-NLS markers]: https://stackoverflow.com/a/40266605\n\n## License\n\n```text\n(c) Copyright 2019 Palantir Technologies Inc. All rights reserved.\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not\nuse this file except in compliance with the License. You may obtain a copy of\nthe License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\nWARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\nLicense for the specific language governing permissions and limitations under\nthe License.\n```\n\nThis is a fork of [google-java-format](https://github.com/google/google-java-format).\nOriginal work copyrighted by Google under the same license:\n\n```text\nCopyright 2015 Google Inc.\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not\nuse this file except in compliance with the License. You may obtain a copy of\nthe License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\nWARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\nLicense for the specific language governing permissions and limitations under\nthe License.\n```\n","funding_links":[],"categories":["Java","Awesome Tools"],"sub_categories":["Languages"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalantir%2Fpalantir-java-format","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpalantir%2Fpalantir-java-format","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalantir%2Fpalantir-java-format/lists"}