How to configure Google Java Code Formatter in Intellij IDEA 17? - Stack Overflow
visual studio code - Google Styleguide Java Format for VSCode - Stack Overflow
Google Java Coding Standards
Any equivalent to the google-java-format plugin?
Can I customize Google Java Style?
How can I check if my code follows Google Java Style?
Is Google Java Style necessary for small projects?
This problem can be solve installing the google-java-format Plugin.
Open plugins window (CTRL+Shift+A): plugins
Click on browse repositories.
Search for google-java-format
Install the plugin.
Restart the IDE.
Enable the plugin executing the action (Ctrl+Shift+A): Reformat with google-java-format Update: in the newer version of the plugin select Reformat since the plugin overrides / enhances the functionality of the standard "Reformat" command.
Additional notes from the google-java-format README
The plugin will be disabled by default. To enable it in the current project, go to File→Settings...→google-java-format Settings (or IntelliJ IDEA→Preferences...→Other Settings→google-java-format Settings on macOS) and check the Enable google-java-format checkbox. (A notification will be presented when you first open a project offering to do this for you.)
To enable it by default in new projects, use File→Other Settings→Default Settings....
As mentioned Here, Download the intellij-java-google-style.xml file from the This Link.
Then in Intellij, go Under Settings -> Editor -> Code Style. there in Scheme settings (settings icon on right side) -> import schemes-> intellij idea code style xml. Select the xml downloaded in first step. then in Scheme dropdown select the GoogleStyle IDE (newly added style). Click on apply and close.
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.
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:
Open file :
C:\Documents and Settings\<USERNAME>\.vscode\extensions\ilkka.google-java-format-1.0.2\out\extension.jsUpdate 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}`, "-", ]);In Settings -> Preferences set executablePath to path to jar archive (google-java-format-1.10.0-all-deps.jar)
Enjoy