Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
Google Java Format is a good formatter for Java code. It can be used with Gradle or as an IntelliJ plugin. The article Integrate Google Java Style Guide in a Java project has a very detailed discussion on how to use Google Java Format.
Format Java Code in IntelliJ IDEA
https://www.jetbrains.com/help/idea/reformat-and-rearrange-code.html
https://stackoverflow.com/questions/42979700/how-to-configure-google-java-code-formatter-in-intellij-idea-17
Configuring Code Style in IntelliJ IDEA
https://www.jetbrains.com/help/idea/code-style-java.html
References
https://github.com/sherter/google-java-format-gradle-plugin/releases