Prettier Plugin for Java is a code formatter that integrates with Prettier to format Java source code. Version 2.8.1 (active development) is released frequently with bug fixes and improvements. It supports Java 8 through 21+, including records, sealed classes, pattern matching, and text blocks. Differentiators: uses Prettier's infrastructure for consistent formatting across languages, respects existing Prettier config, and offers Java-specific options like arrowParens and experimentalOperatorPosition. Requires Prettier v3+ as a peer dependency. Maintained by the JHipster team.
npm install prettier-plugin-javaVerified import paths — ran on the pinned version, not inferred.
Shows installation, Prettier config with plugin, CLI usage, and programmatic formatting with Java parser.
Upgrade Prettier to v3 or later, or use prettier-plugin-java v1.x with Prettier v2.
If you rely on 'avoid', set explicitly in config.
Add plugins array in .prettierrc or pass --plugin=prettier-plugin-java.
Use 'semi' option to control semicolons, not 'trailingComma'.
Run 'npm install --save-dev prettier prettier-plugin-java'.
Ensure you are formatting a .java file or specify parser: 'java' in programmatic API.
Upgrade Prettier to v3: 'npm install prettier@latest'.
Check that the plugin is installed in the same project as Prettier and that Prettier >=3.