{"id":20376,"library":"prettier-plugin-java","title":"Prettier Java Plugin","description":"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.","status":"active","version":"2.8.1","language":"javascript","source_language":"en","source_url":"https://github.com/jhipster/prettier-java","tags":["javascript"],"install":[{"cmd":"npm install prettier-plugin-java","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-java","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-java","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: plugin requires Prettier >=3.0.0 to run.","package":"prettier","optional":false}],"imports":[{"note":"Prettier plugins are usually auto-discovered if installed. For programmatic usage, pass plugin in options.","wrong":"const plugin = require('prettier-plugin-java') and passing to Prettier API incorrectly","symbol":"(plugin, auto-loaded)","correct":"Add plugin to .prettierrc: { \"plugins\": [\"prettier-plugin-java\"] } or use --plugin=prettier-plugin-java"},{"note":"The plugin has no default export. It is used implicitly by Prettier.","symbol":"default (none)","correct":"No explicit import needed; just install and configure in .prettierrc"},{"note":"TypeScript types are bundled with the package. No separate type import needed.","wrong":"import something from 'prettier-plugin-java/types' (does not exist)","symbol":"(types)","correct":"import { Plugin } from 'prettier'; // types for plugin options"}],"quickstart":{"code":"// 1. Install\n// npm install --save-dev prettier prettier-plugin-java\n\n// 2. Configure .prettierrc\n{\n  \"semi\": true,\n  \"singleQuote\": true,\n  \"tabWidth\": 4,\n  \"trailingComma\": \"all\",\n  \"plugins\": [\"prettier-plugin-java\"]\n}\n\n// 3. Run\n// npx prettier --write \"src/**/*.java\"\n\n// Or programmatically:\nimport * as prettier from 'prettier';\nconst code = `public class Hello { public static void main(String[] args) { System.out.println(\"Hello\"); } }`;\nconst formatted = await prettier.format(code, {\n  parser: 'java',\n  plugins: ['prettier-plugin-java']\n});\nconsole.log(formatted);","lang":"typescript","description":"Shows installation, Prettier config with plugin, CLI usage, and programmatic formatting with Java parser."},"warnings":[{"fix":"Upgrade Prettier to v3 or later, or use prettier-plugin-java v1.x with Prettier v2.","message":"Version 2.x requires Prettier >=3.0.0. Not compatible with Prettier v2.","severity":"breaking","affected_versions":"<2.0.0"},{"fix":"If you rely on 'avoid', set explicitly in config.","message":"Option 'arrowParens' default changed to 'always' in v2.7.3 to align with Prettier.","severity":"deprecated","affected_versions":">=2.7.3"},{"fix":"Add plugins array in .prettierrc or pass --plugin=prettier-plugin-java.","message":"Plugin auto-loads if installed in the same project. But if using global Prettier, must specify --plugin or in config.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Use 'semi' option to control semicolons, not 'trailingComma'.","message":"Trailing semicolon placement: the plugin does NOT connect trailing semicolon to prettier's 'trailingComma' option (reverted in v2.7.4).","severity":"gotcha","affected_versions":">=2.7.4"}],"env_vars":null,"search_vec":"'2.8.1':22 '21':38 '8':36 'across':56 'activ':23 'arrowparen':69 'block':47 'bug':29 'class':42 'code':10,20 'config':61 'consist':54 'depend':78 'develop':24 'differenti':48 'exist':59 'experimentaloperatorposit':71 'fix':30 'format':17,55 'formatt':11 'frequent':27 'improv':32 'includ':39 'infrastructur':52 'integr':13 'java':2,7,18,35,65 'java-specif':64 'javascript':84 'jhipster':82 'languag':57 'like':68 'maintain':79 'match':44 'offer':63 'option':67 'pattern':43 'peer':77 'plugin':3,5 'prettier':1,4,15,50,60,73 'record':40 'releas':26 'requir':72 'respect':58 'seal':41 'sourc':19 'specif':66 'support':34 'team':83 'text':46 'use':49 'v3':74 'version':21","created_at":"2026-04-25T11:22:47.621100+00:00","updated_at":"2026-04-25T11:22:47.621100+00:00","problems":[{"fix":"Run 'npm install --save-dev prettier prettier-plugin-java'.","cause":"Plugin not installed or not in node_modules.","error":"Cannot find module 'prettier-plugin-java'"},{"fix":"Ensure you are formatting a .java file or specify parser: 'java' in programmatic API.","cause":"Using .prettierrc without specifying parser and Prettier cannot auto-detect .java file.","error":"Error: No parser and no file path given, couldn't infer a parser."},{"fix":"Upgrade Prettier to v3: 'npm install prettier@latest'.","cause":"Using incompatible Prettier version (v2) with plugin v2.","error":"TypeError: prettier.resolveConfig.sync is not a function"},{"fix":"Check that the plugin is installed in the same project as Prettier and that Prettier >=3.","cause":"Plugin is not a valid Prettier plugin (e.g., installed but not recognized).","error":"Error: Invalid plugin: prettier-plugin-java"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":"https://jhipster.org/prettier-plugin-java","github":"https://github.com/jhipster/prettier-java","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/prettier-plugin-java","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops","testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-24","install_tag":null}}