Google -java-format Code formatter for java Intellij

1.9k views Asked by At

I installed google-java-format in Intellij and made sure its enabled for current project. However its still not working, CTRL+ALT+L, which is by default in Intellij is still working.

Also, does this formatter shows error if formatting is wrong. Like eslint shows error if you leave trailing space in vs code.

Or anyone can suggest better formatter or any other way, guidance is appreciated. Though i make sure to do CTRl+ALT+L before pushing code, if my editor can highlight it in case i miss it, it would be great.

Thanks !!

1

There are 1 answers

1
sampathlk On

Feb 2023 with the latest google-java-format Intellij plugin we need to add following custom VM options. ( Go to Help -> Edit Custom VM Options )

-Xmx2018m
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.code=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

Just follow the updated README file. Updated README file