Google Java Code Formatter
Google Java Style is the most respected coding standard in Java platform. To keep our java code format consistent among developers, auto code formatter is the best options. Google also provides java code formatter to reformat the code.
Release date: January 2021 | Spring Boot: 2.4.x | Revision: 1
Action: Google Java Code Formatter
To comply Google Java Style, google provides google java code formatter to reformat code. We will use google java code formatter to keep our java code format consistent.
Enable Google Code Java Formatter at IntelliJ IDEA
To enable google java code formatter at Intellij IDEA do the following:
-
Install Google Java Formatter IntelliJ IDEA plugin.
-
Enable this plugin from
. -
Now Ctrl+Alt+L (windows) will format code by using google java style guide.
Enable Google Code Java Formatter at Build Script
We will use Spotless gradle plugin to forcefully reformat java code during each code compile. Spotless will first check the code, if code is available for reformat then it will execute reformat. If spotless find nothing to reformat, it will skip the reformat step.
To configure spotless gradle plugin do the following:
-
Add spotless gradle plugin version
gradle.properties
. -
Add spotless gradle plugin at root
build.gradle
. -
Apply spotless gradle plugin and configure during compile time run at dev profile
profile-dev.gradle
. -
Now during code compile time spotless plugin will attempt to reformat our code.
Project Code
-
Github - Google Java Code Formatter