How to share Code Style settings between developers in IntelliJ

后端 未结 4 1984
不思量自难忘°
不思量自难忘° 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:03

    The Settings Repository feature was introduced at IntelliJ IDEA 2016.

    This option helps us to share IDE settings between different computers, including sharing settings between developers.

    The settings are stored at Git repository, for example on GitHub or Bitbucket.

    To setup Git repository we should set URL via Settings Repository menu option.

    The developer can load remote settings, overwrite remote settings or merge local settings with remote ones.

    The structure of Git repository with settings:

    I used personal access token for GitHub authentication.


    More information:

    • Settings Repository
    • Creating a personal access token for the command line
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-08 02:18

    Code Style can be copied to project and saved in .idea/codeStyles to be shared via version control:

    Copy to Project Click this button to create a copy of the current global scheme to the project level. After creating the copy, IntelliJ IDEA suggests to switch to this new scheme at the project level.

    0 讨论(0)
  • 2020-12-08 02:26

    You can create .editorconfig file in Your project (and it can be managed on directory level). More info on https://www.jetbrains.com/help/idea/configuring-code-style.html#editorconfig and https://editorconfig.org/

    With this approach You can keep all Your code style settings in one file and it's not limited to IJ only.

    0 讨论(0)
提交回复
热议问题