Prettier plugin that adds support for formatting Java code. Current stable version is 2.8.4, released with a maintenance cadence. It uses java-parser (Chevrotain-based) to parse Java into a CST and applies Prettier's formatting rules. Key differentiators: integrates seamlessly with Prettier CLI and API, supports custom entrypoints for formatting code snippets, and enforces consistent Java code style across projects. Compatible with Prettier 3.x only.
npm install prettier-plugin-java-for-cjsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Showcases formatting a simple Java class using Prettier API with the java parser.
Upgrade Prettier to ^3.0.0. Run: npm install prettier@^3.0.0 --save-dev
Upgrade to prettier-plugin-java@^2.0.0 and Prettier@^3.0.0
Install globally: npm install -g prettier-plugin-java, or reference plugin via --plugin=./node_modules/prettier-plugin-java
Use one of the valid entrypoints listed in the plugin's options file.
Run npm install prettier-plugin-java --save-dev
Ensure prettier-plugin-java@^2.0.0 with Prettier@^3.0.0, and install the plugin.
Check the options file for valid entrypoints; use one like 'compilationUnit' or 'classBodyDeclaration'.