How to share Code Style settings between developers in IntelliJ

后端 未结 4 1989
不思量自难忘°
不思量自难忘° 2020-12-08 01:21

I would like all developers on my team to use the same default code style settings. We all use IntelliJ 11+ as our IDE and we use git as our source control system.

4条回答
  •  庸人自扰
    2020-12-08 02:10

    I came across this long after the fact, but thought I'd share if anyone ran into this. Add the following to your .gitignore

    # IDE - IntelliJ
    /.idea/*
    # Keep the code styles.
    !/.idea/codeStyles
    /.idea/codeStyles/*
    !/.idea/codeStyles/Project.xml
    !/.idea/codeStyles/codeStyleConfig.xml
    # Keep the inspection levels
    !/.idea/inspectionProfiles
    /.idea/inspectionProfiles/*
    !/.idea/inspectionProfiles/Project_Default.xml

    And of course, make sure your .gitignore also has a ! in front of it so these changes get picked up.

    Basically, gitignore's recursive looking is a little wonky, so the below ignores a directory's contents, except for a subdirectory, then ignores that subdirectory's contents, except for the files we want.

    codeStyleConfig lets you use per project settings, the project file itself is your actual code styles, and I included the Project_Default as it holds the warning levels, which you likely want if you're doing the code style work anyways.

提交回复
热议问题