使用 Ctrl +Alt + s 开启 settings 界面并且选择 Plugins 页面
输入框中输入 google-java-format 点击 Install 按钮进行安装
安装完成后会提示重启 IDEA ,点击确认重启下 IDEA
再次打开 IDEA 之后 选择 Help -> Edit Custom VM Options... 添加下面的内容到该文件
--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
手动重启 IDEA
默认情况下插件被禁用。要启用请打开项目设置,然后单击“google-java-format 设置”并选中“启用 google-java-format”复选框。
至此 IDEA 的 google-java-format 插件已经添加完毕,指接使用 Ctrl +Alt + L 即可按照 插件的规则格式化。不过 google-java-format 的格式化并不能自定义不过无所谓也挺好看。
评论区