I spent some time working on this same problem yesterday. The best and most reliable solution I was able to come up with was to install google-java-format into my path and then use the RunOnSave extension to invoke the binary for files with the .java extension.

Install emeraldwalk/vscode-runonsave:

$ code --install-extension emeraldwalk.RunOnSave

Install google-java-format for your system:

# Example using Homebrew on OS X
$ brew install google-java-format

Configure RunOnSave in Visual Studio Code settings:

{
  "emeraldwalk.runonsave": {
    "commands": [
      {
        "match": "\\.java$",
        "cmd": "google-java-format --replace ${file}"
      },
    ],
  },
}

I describe more of the methodology in this blog post.

Answer from sethvargo on Stack Overflow
Top answer
1 of 7
12

I spent some time working on this same problem yesterday. The best and most reliable solution I was able to come up with was to install google-java-format into my path and then use the RunOnSave extension to invoke the binary for files with the .java extension.

Install emeraldwalk/vscode-runonsave:

$ code --install-extension emeraldwalk.RunOnSave

Install google-java-format for your system:

# Example using Homebrew on OS X
$ brew install google-java-format

Configure RunOnSave in Visual Studio Code settings:

{
  "emeraldwalk.runonsave": {
    "commands": [
      {
        "match": "\\.java$",
        "cmd": "google-java-format --replace ${file}"
      },
    ],
  },
}

I describe more of the methodology in this blog post.

2 of 7
2

google-java-format requires Java 16.0.1 SDK. You have to install it first.

There is an extension ilkka.google-java-format on the Visual Studio Code marketplace, but it is incompatible with current version.

I have to change it this way:

  1. Open file : C:\Documents and Settings\<USERNAME>\.vscode\extensions\ilkka.google-java-format-1.0.2\out\extension.js

  2. Update function provideDocumentRangeFormattingEdits this way:

    return new Promise((resolve, reject) => {
        let stdout = "";
        let stderr = "";
        let child = cp.spawn("java.exe",
            [
                "--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
                "--add-exports", "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
                "--add-exports", "jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
                "--add-exports", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
                "--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
                "-jar",
                executablePath,
                "--lines",
                `${range.start.line}:${range.end.line}`,
                "-",
            ]);
    
  3. In Settings -> Preferences set executablePath to path to jar archive (google-java-format-1.10.0-all-deps.jar)

Enjoy

🌐
Seth Vargo
sethvargo.com › using-google-java-format-with-vs-code
Using google-java-format with VS Code | Seth Vargo
January 12, 2020 - Google publishes a verbose Google Java style guide as well as google-java-format which reformats Java code according to that style guide. The formatter is available as a Java JAR and via popular package managers.
Discussions

References to google-styleguide in formatter documentation
After spending a few hours trying to get a working solution, it seems to me, that the google/styleguide java style is abandoned (last updated 5 years ago), without an offical statement. I found this issue which funnily enough also mentions the vscode-java docs. More on github.com
🌐 github.com
3
February 20, 2023
vscode Google Java style

Why are so many People trying to use vsc for Java. Please dont. You wont be happy with it. Use eclipse or intellij.

More on reddit.com
🌐 r/vscode
16
8
February 12, 2021
java - Google Style formatting - Stack Overflow
"java.format.settings.url": ...va-google-style.xml", "java.format.settings.profile": "GoogleStyle" I am using Eclipse Key Bindings for the record. So when I do Command + Shift + O, I get a small bubble in my Java file saying : Organize imports. However when I click on it I get this error message : Running the contributed command: '_vscode_delegate_... More on stackoverflow.com
🌐 stackoverflow.com
Google Java Format
Is there a way to setup formatting with Google Java Format? Or an entirely new extension is needed which will run the jar formatter on opened file? If so, what would be the best way to implement th... More on github.com
🌐 github.com
10
January 24, 2018
People also ask

How do I set up Google Java Style in IntelliJ/Eclipse/VSCode?
IntelliJ: Use Preferences &gt; Code Style &gt; Java to import the intellij-java-google-style.xml file.Eclipse: In Preferences &gt; Java &gt; Code Style &gt; Formatter, use eclipse-java-google-style.xml.VSCode: Set up formatting in settings and install the google-java-format extension.json.
🌐
studyunicorn.com
studyunicorn.com › blogs › mastering-google-java-coding-style-guide
Master Google Java Style Guide (2026-27 Update)
Can I customize Google Java Style?
There is no way to customize Google's formatter (google-java-format). Use Checkstyle with changed rules instead if you require flexibility.
🌐
studyunicorn.com
studyunicorn.com › blogs › mastering-google-java-coding-style-guide
Master Google Java Style Guide (2026-27 Update)
What is the difference between Google Java Style and Oracle’s conventions?
Google Java Style has more stringent formatting guidelines, a 100-character line limit, and two spaces for indentation (as opposed to Oracle's four). Additionally, it more strictly enforces name rules and uniform brace placement.
🌐
studyunicorn.com
studyunicorn.com › blogs › mastering-google-java-coding-style-guide
Master Google Java Style Guide (2026-27 Update)
🌐
CodingTechRoom
codingtechroom.com › question › -google-java-style-guide-vscode
How to Implement Google Java Style Guide Formatting in Visual Studio Code - CodingTechRoom
How can I configure Visual Studio Code to follow the Google Java Style Guide for formatting my Java code? ... "java.format.settings.url": "https://raw.githubusercontent.com/google/styleguide/gh-pages/javaguide.html" Configuring Visual Studio Code (VSCode) to adhere to the Google Java Style Guide significantly enhances code readability and maintainability.
🌐
Studyunicorn
studyunicorn.com › blogs › mastering-google-java-coding-style-guide
Master Google Java Style Guide (2026-27 Update)
July 6, 2026 - VSCode: Set up formatting in settings and install the google-java-format extension.json. Make use of programs such as google-java-format or incorporate Checkstyle into the Google settings setup.
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
google-java-format - Visual Studio Marketplace
Extension for Visual Studio Code - Yet another simple google-java-format runner
🌐
GitHub
github.com › google › styleguide
GitHub - google/styleguide: Style guides for Google-originated open-source projects · GitHub
Every major open-source project has its own style guide: a set of conventions (sometimes arbitrary) about how to write code for that project. It is much easier to understand a large codebase when all the code in it is in a consistent style. “Style” covers a lot of ground, from “use camelCase for variable names” to “never use global variables” to “never use exceptions.” This project (google/styleguide) links to the style guidelines we use for Google code.
Author: google
🌐
GitHub
github.com › redhat-developer › vscode-java › issues › 2955
References to google-styleguide in formatter documentation · Issue #2955 · redhat-developer/vscode-java
February 20, 2023 - After spending a few hours trying to get a working solution, it seems to me, that the google/styleguide java style is abandoned (last updated 5 years ago), without an offical statement. I found this issue which funnily enough also mentions the vscode-java docs.
Author: redhat-developer
Find elsewhere
🌐
Reddit
reddit.com › r/vscode › vscode google java style
r/vscode on Reddit: vscode Google Java style
February 12, 2021 -

I am trying out vsc for Java development. I would like vsc to create new file templates in the Google style. Is there a way to configure vsc to do this? Or do I have to let it do its thing and then format it afterward?

Thanks.

🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Google Java Format for VS Code - Visual Studio Marketplace
Extension for Visual Studio Code - Visual Studio Code extension to format Java files using google-java-format program to comply with Google Java Style.
🌐
DEV Community
dev.to › marcushellberg › how-to-configure-vs-code-java-formatting-1p10
How to configure VS Code Java formatting - DEV Community
June 30, 2021 - You can either use a formatter like the Google Java Style Guide (which I did) or export your Eclipse profile through Preferences > Java > Code Style > Formatter. Save the file somewhere convenient where it won't get deleted. I chose ~/.vscode/eclipse-java-google-style.xml.
🌐
James Madison University
w3.cs.jmu.edu › spragunr › CS240_F24 › style_guide › style_guide.shtml
Style Guide and Setup Instructions for CS 240
Java 21 is the officially supported version of Java for this course. If you haven't already installed it, you can download the JDK from the Temurin download site. There is no required development environment for this class. The style section below includes instructions for configuring VSCode, Eclipse, or IntelliJ IDEA to support the course style requirements.
🌐
Google
google.github.io › styleguide
Google Style Guides | Style guides for Google-originated open-source projects
Every major open-source project has its own style guide: a set of conventions (sometimes arbitrary) about how to write code for that project. It is much easier to understand a large codebase when all the code in it is in a consistent style. “Style” covers a lot of ground, from “use camelCase for variable names” to “never use global variables” to “never use exceptions.” This project (google/styleguide) links to the style guidelines we use for Google code.
🌐
Domyassignments
domyassignments.com › home › introduction to google java coding style
Introduction to Google Java Coding Style
March 1, 2024 - In the realm of software development, code readability and consistency are crucial for the maintainability and scalability of projects. The Google Java Coding Style represents a set of guidelines designed to standardize Java code, making it more organized and comprehensible for developers across ...
🌐
GitHub
github.com › redhat-developer › vscode-java › issues › 419
Google Java Format · Issue #419 · redhat-developer/vscode-java
January 24, 2018 - Is there a way to setup formatting with Google Java Format? Or an entirely new extension is needed which will run the jar formatter on opened file? If so, what would be the best way to implement th...
Author: redhat-developer
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Google Java Formatter - Visual Studio Marketplace
Extension for Visual Studio Code - Reformats Java source code to comply with Google Java Style for VS Code
Top answer
1 of 2
1

Could you get the xml profile in your mentioned plugin? If yes, make sure you have installed Java extension first, VSCode can use a specified Eclipse xml profile as it's formatter profile.

You can check the setting java.format.settings.url. When it's specified, the given formatter profile will be used in VSCode Java formatting.

Another way to use it is to trigger command Java: Open Java formatter settings, and it will help you generate a default formatter profile, you can change the content to what you want.

2 of 2
0

To directly set "Google Java Style" as "Java's format" on VSCode, please:

1.Install "Extension Pack for Java".

e.g: "Extension Pack for Java v0.9.1" + "Language Support for Java(TM) by Red Hat v0.64.1" for "Java1.8".

Making sure COMPILING, RUNNING and DEBUGGING are successful before "Next Step"!

2.Set the default formatter of Java into "RedHat".

2.1Using hotKeyMap to open the Settings of VSCode, e.g: Ctrl/Cmd + ,

( or Click the logo of VSCode "Code" button and choose "Preference" menu and then click "Setting")

2.2Type "javahome" in the "Search settings" space, then click "Edit in settings.json",

2.3Adding the below code into your "settings.json",

"java.format.settings.url": "https://raw.githubusercontent.com/google/styleguide/gh-pages/intellij-java-google-style.xml",
"java.format.settings.profile": "GoogleStyle",
"java.format.settings.imports.onDemand": false,
"java.format.settings.imports.regexp": "^[a-z.]*",
"[java]": {
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "redhat.java",
    "editor.tabSize": 2
}

2.4Then restart the "VSCode", Using shift + alt/option + f to automatic "Java's format" into "Google Java Style".

END!

🌐
Google
google.github.io › styleguide › javaguide.html
Google Java Style Guide
A Java source file is described as being in Google Style if and only if it adheres to the rules herein. Like other programming style guides, the issues covered span not only aesthetic issues of formatting, but other types of conventions or coding standards as well.
🌐
James Madison University
w3.cs.jmu.edu › spragunr › CS240 › style_guide › style_guide.md
style_guide.md
Java 21 is the officially supported version of Java for this course. If you haven\'t already installed it, you can download the JDK from the Temurin download site. There is no required development environment for this class. The style section below includes instructions for configuring VSCode, Eclipse, or IntelliJ IDEA to support the course style requirements.