0%

intellij-idea-tuning

1. 配置文件路径

  • Linux ~/.config/JetBrains//config
  • OSX ~/Library/Preferences/
  • Windows ~/AppData/Roaming/JetBrains/

2. 配置调整

2.1. 内存

IDEA比较消耗系统资源, 如果觉得IDEA比较慢, 可以适当调整
默认文件是 $IDEA_HOME/bin/idea.vmoptions.
不建议直接修改默认文件, 默认文件在重装后会被覆盖
Help | Edit Custom VM Options 会创建一个复制文件, 可以在这里修改

1
2
-Xms512m
-Xmx2048m

2.2. 行长

Settting | Editor | Code Style
Right Margin : 180

2.3. 自动Make

Setting | build, extecution, deployment | Compiler
Make project automatically checked

2.4. 修改代码字体

Setting | Editor | Colors & Fonts | Font
Save as MyScheme, 修改字体 : 13

2.5. 修改代码提示大小写不敏感&自动弹出提示框

Setting | Editor | General | Code Completion
Case sensitive completion : None
Auto-display code completion : checked

2.6. 自动Make

Preferences | build, extecution, deployment | Compiler
Make project automatically

2.7. 提高编译效率

注意: Eclipse 编译器编译有 lombok 的代码时会报错.

Build, Execution, Deployment | Compiler | Java Compileer
User compiler : Eclipse
Processed on errors : checked

2.8. tomcat 下乱码

Run | Edit Configuration | tomcat | Startup/Connection

name value
JAVA_TOOL_OPTIONS -Dfile.encoding=UTF-8

2.9. 修改属性资源文件(.properties)的编码

Editor | File Encoding
Transparent native-to-ascii conversion : checked

2.10. 开启序列化 serialVersionUID 检测

Setting | Inspections | Serialization issues
serialzable class without “serialVersionUID” : checked

2.11. 点击 stop 时立即关闭调试线程

Build, Execution, Deployment | Debugger |
Java | kill the debugger process immediately : checked

2.12. 允许多个实例

Edit Configuration
Single instance only : unchecked

2.13. 字段 Import 类型

Setting | Editor | Auto Import

Optimize import on the fly : checked
Add unambiguous import on the fly : checked

2.14. 多行Tab

Setting | Editor | Editor Tabs
Show tabs in one row : unchecked

2.15. 关闭编辑窗口滚动条悬停时的代码透镜

Setting | Editor | General | Appearance
Show code lens on scrollbar honver : unchecked

2.16. 签名

Preferences | Editor | File and Code Templates
Includes | File Header

1
2
3
4
/**
* @author ${USER}
* @date ${YEAR}-${MONTH}-${DAY} ${HOUR}:${MINUTE}
*/

2.17. Maven 并行编译

File | Settings | Build, Execution, Deployment | Build Tools | Maven
Thread count: 2C
查看 CPU 是 i7-1051U, 是 4 核 8 线程的, 所以设置为 2C, 标识一个核心开启2个线程.

2.18. gitignore

1
2
3
4
5
6
7
8
9
10
11
12
13
# IntelliJ project files
.DS_Store/
.idea/
out/
gen/
dst/
target/
.mvn/

mvnw
mvnw.cmd

*.iml

2.19. 使用外部注解

Intellij IDEA 的注解, 辅助开发, 加强参数效验

  1. 开启外部注解:

Settings | PreferencesEditor | Code Style | Java | Code Generation
Use external annotations : checked

  1. 配置外部注解存放文件
  • 方式 1: 模块级配置

Project Structure | Modules | Paths | External Annotations

  • 方式 2: 项目级配置

Project Structure | SDKs | Annotations

2.20. 同步配置

IDEA 需要安装 IDE Settings Sync & Settings Repository 2个插件, 一般默认自带了.

File / Settings Repository 页面中设置同步存放的 git 地址, 然后点击 Overwrite Local. 如果想要储存库保留远程设置和本地设置的组合, 可以点击 Merge. 如果检测到任何冲突, 将显示一个对话框, 可以在其中解决这些冲突. 如果要使用本地设置覆盖远程设置, 请单击点击 Overwrite Remote.

2.21. 性能优化

2.21.1. 去除不必要的代码检测

Settings / Build, Execution, Deployment / Compiler / Kotlin compiler
Keep compiler process alive between invocations -> unchecked

Inspections
Spellings -> unchecked

2.21.2. 优化启动速度

配置 idea64.vmoptions 参数

config/idea64.vmoptions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
-Xms512m
-Xmx2048m
-XX:ReservedCodeCacheSize=240m
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
-ea
-XX:CICompilerCount=2
-Dsun.io.useCanonPrefixCache=false
-Djava.net.preferIPv4Stack=true
-Djdk.http.auth.tunneling.disabledSchemes=""
-XX:+HeapDumpOnOutOfMemoryError
-XX:-OmitStackTraceInFastThrow
-Djdk.attach.allowAttachSelf
-Dawt.useSystemAAFontSettings=lcd
-Dsun.java2d.renderer=sun.java2d.marlin.MarlinRenderingEngine
-Dsun.tools.attach.tmp.only=true
-Duser.language=en
-javaagent:/home/raven/Documents/script/run-config/idea/jetbrains-agent/jetbrains-agent.jar

2.21.3. 加大编译内存

Settings / Build, Execution, Deployment / Compiler
Build process heap size: 1024

2.21.4. 加大 Maven 导入内存

Settings / Build, Execution, Deployment / Build Tools / Maven / Importing
VM options for importer: -Xmx1024m