Title: Add a Maven plugin with format and check goals · Issue #26 · openjavaformat/open-java-format · GitHub
Open Graph Title: Add a Maven plugin with format and check goals · Issue #26 · openjavaformat/open-java-format
X Title: Add a Maven plugin with format and check goals · Issue #26 · openjavaformat/open-java-format
Description: Why Maven users have no way to run open-java-format from their build today. palantir-java-format never had a Maven plugin. palantir#327 has asked for Maven instructions since 2020, and in palantir#832 the maintainers point Maven users to...
Open Graph Description: Why Maven users have no way to run open-java-format from their build today. palantir-java-format never had a Maven plugin. palantir#327 has asked for Maven instructions since 2020, and in palantir#...
X Description: Why Maven users have no way to run open-java-format from their build today. palantir-java-format never had a Maven plugin. palantir#327 has asked for Maven instructions since 2020, and in palantir#...
Opengraph URL: https://github.com/openjavaformat/open-java-format/issues/26
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add a Maven plugin with format and check goals","articleBody":"### Why\n\nMaven users have no way to run open-java-format from their build today.\n\n- palantir-java-format never had a Maven plugin. palantir/palantir-java-format#327 has asked for Maven instructions since 2020, and in palantir/palantir-java-format#832 the maintainers point Maven users to Spotless.\n- Spotless is not a route for this project. Its `palantirJavaFormat` step hardcodes `com.palantir.javaformat:palantir-java-format`, and diffplug/spotless#3084, which adds an `openJavaFormat` step, was closed. The details are at https://openjavaformat.dev/get-started/spotless/.\n- A search of Maven Central found no Maven plugin for palantir-java-format either.\n\n### Proposal\n\nA plugin `dev.openjavaformat:open-java-format-maven-plugin`, released together with the formatter and under the same version, with two goals modelled on [spotify/fmt-maven-plugin](https://github.com/spotify/fmt-maven-plugin):\n\n| Goal | Default phase | What it does |\n| --- | --- | --- |\n| `format` | `process-sources` | Formats the Java files in place |\n| `check` | `verify` | Fails the build and lists the files that are not formatted |\n\n```xml\n\u003cplugin>\n \u003cgroupId>dev.openjavaformat\u003c/groupId>\n \u003cartifactId>open-java-format-maven-plugin\u003c/artifactId>\n \u003cversion>\u003c!-- the formatter version -->\u003c/version>\n \u003cexecutions>\n \u003cexecution>\n \u003cgoals>\n \u003cgoal>check\u003c/goal>\n \u003c/goals>\n \u003c/execution>\n \u003c/executions>\n\u003c/plugin>\n```\n\nFrom the command line the prefix gives `mvn open-java-format:format` and `mvn open-java-format:check`.\n\nAs few settings as possible, in line with a formatter that has none: the source roots, which default to the module's compile and test source roots, includes and excludes, and `skip`. The style is always OJF.\n\n### How the formatter runs\n\nThe formatter needs javac's internal packages exported. Running it inside the Maven JVM would make every project add the five `--add-exports` flags to `.mvn/jvm.config`, which is what [Cosium/git-code-format-maven-plugin](https://github.com/Cosium/git-code-format-maven-plugin) asks its users to do. Two ways avoid that:\n\n- **Fork one JVM per module.** Start the current JDK with the flags and the formatter's classpath, and hand all files of the module to `com.palantir.javaformat.java.Main` in a single call through an `@argfile`: `--replace` for `format`, `--dry-run --set-exit-if-changed` for `check`. `BootstrappingFormatterService` in `open-java-format-jdk-bootstrap` already builds this command line, although it starts one process per file. spotify/fmt-maven-plugin forks by default for the same reason, see its `forkMode`.\n- **The native binary** from `open-java-format-native`, as the Gradle plugin does with `openjavaformat.native.formatter`, on Linux with glibc and on macOS.\n\nThe formatter comes from the plugin's own dependencies, so it needs nothing from the project's repositories. That is the principle of #20 for the Gradle plugin.\n\n### Building it here\n\nThe repository builds with Gradle, and a Maven plugin needs a plugin descriptor. `org.gradlex.maven-plugin-development` generates it from the mojo annotations; the alternative is a small Maven build for this one module. Publishing goes through the existing JReleaser conventions together with the other jars.\n\n### Done when\n\n- the plugin is on Maven Central under the formatter's version;\n- an integration test runs real `mvn` on a sample multi-module project against the locally published plugin, for both goals, on Java 21 and without `.mvn/jvm.config`;\n- the output of `format` is byte-identical to the command line with `--ojf`;\n- the website gets a Maven page under Get started, and the Maven parts of the Spotless and Migrate pages point to it.\n\n### Related\n\n- palantir/palantir-java-format#327 and palantir/palantir-java-format#832\n- diffplug/spotless#3084\n- Cosium/git-code-format-maven-plugin has a formatter SPI, `CodeFormatterFactory`, so an open-java-format formatter for it would be a smaller, complementary step.\n","author":{"url":"https://github.com/abashev","@type":"Person","name":"abashev"},"datePublished":"2026-09-21T15:24:05Z","url":"https://github.com/openjavaformat/open-java-format/issues/26"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b40e4868-6fea-11e3-3bdf-a08bc7212001 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DA04:1F7D:31C5D3:426903:6AFBC983 |
| html-safe-nonce | 3f679c6219dd11a0885f9eb68ef0b56b270ce4df18f9cf56bb7c68fbb5f97b27 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQTA0OjFGN0Q6MzFDNUQzOjQyNjkwMzo2QUZCQzk4MyIsInZpc2l0b3JfaWQiOiI0MTcxNDQyMTE0MjE2NTc3NDExIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8295ef416ebdc94139bf97f096629e435abd40e8f07cd0e466d2765d14f945a1 |
| hovercard-subject-tag | issue:5528980023 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/openjavaformat/open-java-format/26/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f96921610f273b2c8fca32046d922e3fe1fcb02cf59f1917702bb4e07b434221/openjavaformat/open-java-format/issues/26 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f96921610f273b2c8fca32046d922e3fe1fcb02cf59f1917702bb4e07b434221/openjavaformat/open-java-format/issues/26 |
| og:image:alt | Why Maven users have no way to run open-java-format from their build today. palantir-java-format never had a Maven plugin. palantir#327 has asked for Maven instructions since 2020, and in palantir#... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | abashev |
| hostname | github.com |
| expected-hostname | github.com |
| None | d440bda0d812801778b27bfe9f7c1ce9ff22420c73f6f95150c4fcbca311c50b |
| turbo-cache-control | no-preview |
| go-import | github.com/openjavaformat/open-java-format git https://github.com/openjavaformat/open-java-format.git |
| octolytics-dimension-user_id | 325177626 |
| octolytics-dimension-user_login | openjavaformat |
| octolytics-dimension-repository_id | 1288055459 |
| octolytics-dimension-repository_nwo | openjavaformat/open-java-format |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | true |
| octolytics-dimension-repository_parent_id | 214273098 |
| octolytics-dimension-repository_parent_nwo | palantir/palantir-java-format |
| octolytics-dimension-repository_network_root_id | 214273098 |
| octolytics-dimension-repository_network_root_nwo | palantir/palantir-java-format |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2c43021aed8695990c86c0eaaedc600bfeffec36 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width