Registry / devops / prettier-plugin-java

prettier-plugin-java

JSON →
library2.8.1jsnpmunverified

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-java
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-JA
P
prettier-plugin-java
devopsjavascriptv2.8.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

(plugin, auto-loaded)
Add plugin to .prettierrc: { "plugins": ["prettier-plugin-java"] } or use --plugin=prettier-plugin-java
const plugin = require('prettier-plugin-java') and passing to Prettier API incorrectly
Prettier plugins are usually auto-discovered if installed. For programmatic usage, pass plugin in options.
default (none)
No explicit import needed; just install and configure in .prettierrc
The plugin has no default export. It is used implicitly by Prettier.
(types)
import { Plugin } from 'prettier'; // types for plugin options
import something from 'prettier-plugin-java/types' (does not exist)
TypeScript types are bundled with the package. No separate type import needed.

Shows installation, Prettier config with plugin, CLI usage, and programmatic formatting with Java parser.

// 1. Install // npm install --save-dev prettier prettier-plugin-java // 2. Configure .prettierrc { "semi": true, "singleQuote": true, "tabWidth": 4, "trailingComma": "all", "plugins": ["prettier-plugin-java"] } // 3. Run // npx prettier --write "src/**/*.java" // Or programmatically: import * as prettier from 'prettier'; const code = `public class Hello { public static void main(String[] args) { System.out.println("Hello"); } }`; const formatted = await prettier.format(code, { parser: 'java', plugins: ['prettier-plugin-java'] }); console.log(formatted);
Debug
Known issues
breakingVersion 2.x requires Prettier >=3.0.0. Not compatible with Prettier v2.
fix
Upgrade Prettier to v3 or later, or use prettier-plugin-java v1.x with Prettier v2.
affects: <2.0.0
deprecatedOption 'arrowParens' default changed to 'always' in v2.7.3 to align with Prettier.
fix
If you rely on 'avoid', set explicitly in config.
affects: >=2.7.3
gotchaPlugin auto-loads if installed in the same project. But if using global Prettier, must specify --plugin or in config.
fix
Add plugins array in .prettierrc or pass --plugin=prettier-plugin-java.
affects: >=2.0.0
gotchaTrailing semicolon placement: the plugin does NOT connect trailing semicolon to prettier's 'trailingComma' option (reverted in v2.7.4).
fix
Use 'semi' option to control semicolons, not 'trailingComma'.
affects: >=2.7.4
Errors
Common errors & fixes
Cannot find module 'prettier-plugin-java'
Plugin not installed or not in node_modules.
fix
Run 'npm install --save-dev prettier prettier-plugin-java'.
Error: No parser and no file path given, couldn't infer a parser.
Using .prettierrc without specifying parser and Prettier cannot auto-detect .java file.
fix
Ensure you are formatting a .java file or specify parser: 'java' in programmatic API.
TypeError: prettier.resolveConfig.sync is not a function
Using incompatible Prettier version (v2) with plugin v2.
fix
Upgrade Prettier to v3: 'npm install prettier@latest'.
Error: Invalid plugin: prettier-plugin-java
Plugin is not a valid Prettier plugin (e.g., installed but not recognized).
fix
Check that the plugin is installed in the same project as Prettier and that Prettier >=3.
Upgrade
Version history
2.8.1latest on npm
Audit
Dependencies
prettierrequiredPeer dependency: plugin requires Prettier >=3.0.0 to run.
Agent activity
4 hits · last 30 days
node
4
Resources
prettier-plugin-java — npm install prettier-plugin-java · libregistry