Used same settings in .prettierrc and settings.json file except

"[java]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
},

and added default formatter for java files as follows

  1. Open command Palette... Ctrl + Shift + P (mac command + shift + P) and
  2. search Format Document With...
  3. select Configure Default Formatter...
  4. choose Language Support for Java(TM) by Red Hat

Working sample

Now if I add following in settings.json

"[java]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
},

got the same issue as of yours

So the solution will be to remove above settings from the settings.json file.

settings.json file

{
    "files.eol": "\n",
    "terminal.explorerKind": "external",
    "terminal.integrated.shell.osx": "/bin/zsh",
    "editor.minimap.enabled": true,
    "workbench.colorTheme": "Visual Studio Dark",
    "editor.fontSize": 14,
    "editor.fontFamily": "source code pro, Menlo, Monaco, 'Courier New', monospace",
    "terminal.external.osxExec": "iterm.app",
    "window.zoomLevel": 1,
    "go.useLanguageServer": true,
    "editor.formatOnSave": true,
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "breadcrumbs.enabled": false 
}

P.S. Make sure Java Extension Pack vscjava.vscode-java-pack is installed, used v0.12.1

Ref:

  1. https://github.com/redhat-developer/vscode-java/issues/220
  2. Beautify / Format Java code in Visual Studio Code
  3. https://code.visualstudio.com/docs/java/java-linting
  4. https://github.com/jhipster/prettier-java
  5. https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
Answer from dkb on Stack Overflow
🌐
npm
npmjs.com › package › prettier-plugin-java
prettier-plugin-java - npm
Prettier is an opinionated code formatter which forces a certain coding style. It makes the code consistent through an entire project. This plugin allows the support of Java on Prettier.
      » npm install prettier-plugin-java
    
Published   Jan 08, 2026
Version   2.8.1
🌐
GitHub
github.com › jhipster › prettier-java
GitHub - jhipster/prettier-java: Prettier Java Plugin · GitHub
A Prettier plugin must first parse the source code of the target language into a traversable data structure (Usually an Abstract Syntax Tree) and then print out that data structure in a "pretty" style. Prettier-Java uses a Java-Parser implemented in JavaScript using the Chevrotain Parser Building Toolkit for JavaScript.
Author   jhipster
🌐
JHipster
jhipster.tech › prettier-java
Prettier Java
Try It OnlineInstall Prettier Java · An opinionated Java code formatter · Integrates with most editors · Your code is formatted on save · No need to discuss style in code review ·
Top answer
1 of 1
2

Used same settings in .prettierrc and settings.json file except

"[java]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
},

and added default formatter for java files as follows

  1. Open command Palette... Ctrl + Shift + P (mac command + shift + P) and
  2. search Format Document With...
  3. select Configure Default Formatter...
  4. choose Language Support for Java(TM) by Red Hat

Working sample

Now if I add following in settings.json

"[java]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
},

got the same issue as of yours

So the solution will be to remove above settings from the settings.json file.

settings.json file

{
    "files.eol": "\n",
    "terminal.explorerKind": "external",
    "terminal.integrated.shell.osx": "/bin/zsh",
    "editor.minimap.enabled": true,
    "workbench.colorTheme": "Visual Studio Dark",
    "editor.fontSize": 14,
    "editor.fontFamily": "source code pro, Menlo, Monaco, 'Courier New', monospace",
    "terminal.external.osxExec": "iterm.app",
    "window.zoomLevel": 1,
    "go.useLanguageServer": true,
    "editor.formatOnSave": true,
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "breadcrumbs.enabled": false 
}

P.S. Make sure Java Extension Pack vscjava.vscode-java-pack is installed, used v0.12.1

Ref:

  1. https://github.com/redhat-developer/vscode-java/issues/220
  2. Beautify / Format Java code in Visual Studio Code
  3. https://code.visualstudio.com/docs/java/java-linting
  4. https://github.com/jhipster/prettier-java
  5. https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
🌐
GitHub
github.com › jhipster › prettier-java › blob › main › docs › advanced_usage.md
prettier-java/docs/advanced_usage.md at main · jhipster/prettier-java
# Prettier configuration plugins: - prettier-plugin-java overrides: - files: - "*.java" options: printWidth: 140 tabWidth: 4 useTabs: false trailingComma: "none"
Author   jhipster
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Prettier Java Plugin - Visual Studio Marketplace
Extension for Visual Studio Code - Format Java files with Prettier using prettier-plugin-java.
🌐
GitHub
github.com › jhipster › prettier-java › tree › main › packages › prettier-plugin-java
prettier-java/packages/prettier-plugin-java at main · jhipster/prettier-java
Prettier is an opinionated code formatter which forces a certain coding style. It makes the code consistent through an entire project. This plugin allows the support of Java on Prettier.
Author   jhipster
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Prettier Java formatter - Visual Studio Marketplace
Extension for Visual Studio Code - Integration of Prettier Java into Visual Studio Code
Find elsewhere
🌐
GitHub
github.com › jhipster › prettier-java › blob › main › packages › prettier-plugin-java › README.md
prettier-java/packages/prettier-plugin-java/README.md at main · jhipster/prettier-java
Prettier is an opinionated code formatter which forces a certain coding style. It makes the code consistent through an entire project. This plugin allows the support of Java on Prettier.
Author   jhipster
🌐
JHipster
jhipster.tech › installation
Installation | Prettier Java
npm install --save-dev --save-exact prettier prettier-plugin-java · yarn add --dev --exact prettier prettier-plugin-java · pnpm add --save-dev --save-exact prettier prettier-plugin-java · Requirements ·
🌐
Reddit
reddit.com › r/visualstudiocode › prettier extension doesn't work with java
r/VisualStudioCode on Reddit: Prettier extension doesn't work with java
May 18, 2023 -

I installed Prettier and the java extensions that I need set prettier as my default formatter. I just to see that java doesn't use prettier as a formatter even though I set it as default. After looking into it some more I found out that I can force java documents to use prettier as a formatter by setting it in the settings.json of vscode but it still doesn't format it.

🌐
Koliseo.blog()
blog.koliseo.com › prettier-for-java
Prettier for Java
February 12, 2021 - Name: Prettier Java File Type: Java Program: npx Arguments: prettier --write $FilePath$ Output path to refresh: $FilePath$ Trigger the watcher on external changes: checked Autosave edited files to trigger the watcher: deactivated
🌐
CodeSandbox
codesandbox.io › examples › package › prettier-plugin-java
prettier-plugin-java examples - CodeSandbox
Use this online prettier-plugin-java playground to view and fork prettier-plugin-java example apps and templates on CodeSandbox.
🌐
GitHub
github.com › HubSpot › prettier-maven-plugin
GitHub - HubSpot/prettier-maven-plugin
Maven plugin for running prettier-java during a build.
Starred by 122 users
Forked by 22 users
Languages   Java 99.9% | JavaScript 0.1%
🌐
JetBrains
jetbrains.com › help › idea › prettier.html
Prettier | IntelliJ IDEA Documentation
To use the Prettier tool with Java, refer to Prettier-Java plugin that you can add to your Java project.
🌐
GitHub
github.com › jhipster › prettier-java › blob › main › README.md
prettier-java/README.md at main · jhipster/prettier-java
A Prettier plugin must first parse the source code of the target language into a traversable data structure (Usually an Abstract Syntax Tree) and then print out that data structure in a "pretty" style. Prettier-Java uses a Java-Parser implemented in JavaScript using the Chevrotain Parser Building Toolkit for JavaScript.
Author   jhipster
🌐
DEV Community
dev.to › m4nu56 › prettier-to-format-your-java-codebase-3f7i
Prettier to format your Java codebase - DEV Community
May 27, 2020 - The community developped a plugin for java that uses node under the hood to format your java classes. Plugin is available on github. ... But that's not very convenient. We don't want to ask every developer that will work on the codebase to install the plugin and run it itself. Thanksfully a maven plugin has been developped by HubSpot. It's also available on github. The plugin comes bundled with node, prettier and the prettier-java plugin so developers don't have to install it themselves and it can be executed inside a maven goal.