How to share Code Style settings between developers in IntelliJ

Intellij Idea

Intellij Idea Problem Overview


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.

What is the easiest way to make sure they're all using the same settings? I thought there would be a way to check in the style settings into the project and have their editors discover them automatically, but that doesn't seem to be the case.

PS. I don't mind if developers consciously override some of the default settings with their own preferences, but I do want to make sure that we all at least start from a common set of default settings.

Intellij Idea Solutions


Solution 1 - Intellij Idea

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.

Solution 2 - Intellij Idea

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.

Calling settings

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

Set url and choose action

The structure of Git repository with settings:

Git repository structure

I used personal access token for GitHub authentication.


More information:

Solution 3 - Intellij Idea

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.

Solution 4 - Intellij Idea

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionemmbyView Question on Stackoverflow
Solution 1 - Intellij IdeaCrazyCoderView Answer on Stackoverflow
Solution 2 - Intellij IdeaAlex KView Answer on Stackoverflow
Solution 3 - Intellij IdeaWes WinnView Answer on Stackoverflow
Solution 4 - Intellij IdeacyprianView Answer on Stackoverflow