Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need a strategy to put Intellij IDEA project files in Git

Need a strategy to put Intellij IDEA project files into Git.

The main question is how to avoid merge conflicts between branches if idea project files are in git.

Another question is it convenient to keep them in git?

like image 214
Vladimir Avatar asked Aug 16 '10 16:08

Vladimir


1 Answers

How to avoid merge

You can protect some files from merges with merge managers.

Is it convenient to keep them in git

Yes, like the ones for Eclipse. See Sharing IntelliJ IDEA Project Files in Version Control.
That is, provided they are:

  • without any absolute path
  • text files only
  • typically .ipr and .iml
  • Rule #1 - Check-in the .ipr and .iml files
  • Rule #2 - Set an ignore flag for the .iws file (your workspace file). All proper VCSs allow you to do this.
  • Rule #3 - Make IDEA Project Variables for all the variables that vary (it's kinda the definition of variable, you know). Some common variables you'll probably need are "Tomcat Home", "Groovy Home", and "JDK Version".

The Gotchas - There are a few gotcha's to be aware of...

  • Using multiple versions of IDEA is not well supported. Most new versions, even minor releases, try to write some extra info to the project files.
  • Making the JDK Name variable can be somewhat confusing, as it is not a path on your disk. IDEA keeps track globally (for all projects) of your installed JDKs, and each one is given a name. It is easy to find the place in the .ipr where this is specified, but it is not easy to explain to users what their's should be set to. It needs to be the name of an entry from your SDKs in Settings.
  • Also, changing the inspection profiles can modify the project.
    The inspections are the codestyle to the project, so it may make sense to have them baked into the .ipr. However, this is an optional place to put them. An inspection profile can be shared or not. If it is shared then it is written to the .ipr, otherwise it is an external file.
  • Lastly, adding words to the spell checker will add the word to the .ipr file, with a key of your username. I opened a bug for this, as I feel a user's name should never go in the project file, but the JetBrains guys feel that this is OK considering that switching to the ".idea" alternate project layout will separate the files out and avoid the issue
like image 110
VonC Avatar answered Oct 21 '22 13:10

VonC