Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices for IntelliJ IDEA 9 + Maven + Version control

The project is using Maven so the POM files are the main sources of project info. There are some useful settings in the project files which would be nice to keep.

OTOH IDEA seems to create too many redundant changes in the project file structure which pollutes the SVN history and sometimes creates conflicts.

Should I keep the .idea directory and the *.iml files under version control? in full? in part?

Update: So the best practice I have found working for me and my team is so far:

  1. Check in all IDEA files, *.iml and .idea directories. They contain valuable information and it's a waste of time to recreate it each time you update.
  2. Create private branch for every developer
  3. cd into .idea directory
  4. svn switch it to its private branch counterpart
  5. Don't check in IDEA files on regular commits -- they pollute history. Check them in on special commits.

This way, you keep the content of .idea directory in version control but keep it out of the way of regular commits. Any developer can have access to anybody else's IDEA directories.

Update 2: Since this question was written, I have changed my practice to not checking in any IntelliJ files into the version control, as advised by many responders. This is my current practice for both Maven and Gradle. The tools have developed to the point that the critical information can always be reproduced from the original .POM or .gradle files. When the files change, the IDE tracks changes reliably so you don't lose your IDE files that often so there is no need to check them in.

Update 3: 7 years after asking this question it seems to be still relevant. The same best practices apply to Gradle as well (probably SBT, too): don't check IDE files in, recreate them as necessary from the basic POM, .gradle or SBT files.

like image 341
Sasha O Avatar asked Oct 31 '09 19:10

Sasha O


People also ask

How do I use version control in IntelliJ?

IntelliJ IDEA supports a directory-based versioning model, which means that each project directory can be associated with a different version control system. Press Ctrl+Alt+S to open the IDE settings and select Version Control | Directory Mappings.

Which version of Maven is installed IntelliJ?

Go to File -> Settings and use the search bar to find maven settings. There you can find the maven version (usually against the field "Maven home directory" ).

How do I run a multi module Maven project in IntelliJ?

In the Project tool window, right-click the project folder and select New | Module. Alternatively, from the main menu, select File| New | Module to open the New Module wizard. If you used main menu to add a module then the process of adding a module is the same as Creating a new Maven project.

Does IntelliJ build use Maven?

Maven projects IntelliJ IDEA lets you manage Maven projects. You can link, ignore projects, synchronize changes in Maven and IntelliJ IDEA projects, and configure the build and run actions.


2 Answers

Short answer: don't put these files in the source control repository as you can "generate" them (and this is even more true if you don't need them, if they are annoying, if they can break others environment).

I personally use the following values for svn:ignore:

target 
*~ 
*.log 
.classpath 
.project 
*.ipr 
*.iws 
*.iml 
.settings 
like image 105
Pascal Thivent Avatar answered Oct 23 '22 15:10

Pascal Thivent


One of the great things about Maven is that the tool support exists for turning a POM into a native project in Eclipse, Idea and Netbeans. If you have a pom, you can create a native project pretty quickly.

For that reason, I wouldn't check in .idea or *.iml files under source control any more than I would check in RMI stubs or class files.

like image 15
sal Avatar answered Oct 23 '22 14:10

sal