Eclipse、IntelliJ IDEA代码格式统一

     工欲善其事必先利其器,Java开发离不了的工具Eclipse、IntelliJ IDEA,但是两个工具使用者的代码格式时常不一致,为此导致项目代码格式混乱、版本控制冲突也是常有的事,给项目管理带来极大的不方便。一般情况下除非项目组有共同指定的代码格式,大多情况都遵循google codeStyle(https://github.com/google/styleguide)。下面对两大工具的设置做些说明。

(一)、Eclipse设置goolge codeStyle

 1、导入方法:Eclipse->window->preferences->Java->Code Style->Formatter->Import 选择eclipse-java-google-style.xml文件,选择GoogleStyle。

 

 

(二)、IntelliJ IDEA设置goolge codeStyle

1、首先下载文件:intellij-java-google-style.xml。

2、找到该路径(C:\Users\自己的登录名 \.IntelliJIdea15\config\codestyles), 如果你的目录下没有codestyles文件夹,请自己创建,然后将intellij-java-google-style.xml文件复制到该处。

3、打开IntelliJ IDEA,找到setting 设置,选择GoogleStyle。

 

另外Intellij idea还可通过安装插件的形式使用Eclipse的格式化配置文件(eclipse-java-google-style.xml)

1,安装插件:
网络安装:选择Setting =>Plugins=>Browse repositories,搜索Eclipse即可出现,点击左上角的Download and Install安装。安装之后重启Intellij,即可在Setting =>Eclipse Code Formatter找到配置项。
硬盘安装(推荐):Setting =>Plugins=>Install plugin from disk,选中下载好的安装包【EclipseFormatter.zip】安装,重启后生效;
2,配置插件:
选择Setting =>Eclipse Code Formatter,勾选Use the Eclipse-code-formatter,并在Eclipse Java Formatter config file选择Eclipse用的code-style.xml文件,这个选项会决定格式化代码的方式。
同时配置Import order的From File也为Eclipse用的code-style.xml文件,这个选项会决定组织import区域的方式。
3,使用插件

posted @ 2018-02-25 20:51  joenali  阅读(1456)  评论(0编辑  收藏  举报