views:

2951

answers:

6

Which eclipse files is it appropriate to put under source control, aside from the sources obviously. In my project, specifically, I'm wondering about:

.metadata/*
project-dir/.project
project-dir/.classpath
project-dir/.settings/*

If there are any of these for which is depends, please explain your guidelines.

+21  A: 

Metadata should not be managed in source control, they contain mostly data relevant to your workspace.

The only exception is the .launch xml files (launcher definition).

They are found in

[eclipse-workspace]\.metadata\.plugins\org.eclipse.debug.core\.launches

And should be copied into your project directory: when your project is refreshed, those configurations will be displayed in the "Run configuration" dialog.
That way, those launch parameter files can be also managed into the SCM.

(Warning: do uncheck the option "Delete configurations when associated resource is deleted" in the Run/Launching/Launch Configuration preference panel: it is common ot soft-delete a project in order to import it back again, to force a reinitialization of the eclipse metadata,... but this option, if checked, will removed your detailed launch parameters!)

project-dir/.project
project-dir/.classpath
project-dir/.settings/* 

should be in your SCM.

The goal is that anyone can checkout/update his/her SCM workspace and import the eclipse project into the eclipse workspace.

For that, you want to use only relative paths in your .classpath, using linked resources.

Note: it is better if project-dir refers to an "external" project directory, not a directory created under the eclipse workspace. That way, the two notions (eclipse workspace vs. SCM workspace) are clearly separated.


As ipsquiggle mentions in the comment, and as I have alluded to in an old answer, you can actually save the launching configuration as shared file directly in your project directory. All launching configuration can then be versioned like the other project files.

(From the blog post Tip: Creating and Sharing Launch Configurations from KD)

alt text

VonC
A (IMO) much better work flow to working with anything in .metadata for the .launch files, is: when you edit a launch configuration, on the `common` tab, choose `Save as > shared file`. This directly drops it in the project folder, so it can be SCM'd with the rest of the project.
Ipsquiggle
@lpsquiggle: good point. I have completed my answer to better reflect that possibility.
VonC
A: 

I'd say none of them. They most likely contain information that is relevant only to your workstation (I'm thinking about paths for libraries and all). Also what if someone in your team is not using Eclipse?

agnul
Nope, you can have relative paths in your .classpath. See http://stackoverflow.com/questions/300328#300346.
VonC
+3  A: 

I am currently working on a project where we have the .project and .cproject files under source control. The idea was that settings related to library paths and link directives would propagate across the team.

In practice it hasn't worked very well, merges almost always come back in a conflicted state which need to be deconflicted outside of eclipse and then the project closed and reopened for the changes to take effect.

I wouldn't recommend keeping them in source control.

pdemarest
+1  A: 

Some projects, like those using Maven, like to generate the .project files based on POMs.

That said, other than that - .metadata should NOT be in source control. Your project will have to make a determination about whether projectdir/.settings does, based on how you plan to manage standards and such. If you can honestly trust your developers to set up their environment based on the standard, and you don't have to customize anything special for any project, then you don't need to put them in. Me, I recommend configuring every project specifically. This allows devs to work on multiple projects' stuff in the same workspace without having to change default settings back and forth, and it makes the settings very explicit, overriding whatever their default settings are to match the project's standards.

Only difficult part is making sure they all stay in sync. But in most cases you can copy the .settings files from project to project. If there are any you specifically don't want in source control, do the equivalent of setting svn:ignore for them, if your SCM supports it.

John Stoneham
We use Maven 1 and 2, and it only generates the .project file if you ask it to. And even if you do, it does so based on the contents of the POM, so if another developer has already done that step for you and checked the result into version control, why not take advantage of that?
Andrew Swan
+2  A: 

It's worth nothing that CDT configuration files are not source-control-friendly, there's a bug filed for .cproject files changing very frequently and causing conflicts, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=226457

Diaa Sami
A: 

The .classpath file is definitively a good candidate for checking into scm as setting it by hand can be a lot of work and will be difficult for new devs getting into the project. It is true it can be generated from other sources, in which case you would check in the other source.

As for .settings, it depends on the settings. This is a grey area, but some settings are almost mandatory and it is convenient to be able to check out a project, import it in Eclipse and have everything set up and good to go.

At our project, we therefore maintain a copy of the .settings folder called CVS.settings and we have an ant task to copy it to .settings. When you get the project from CVS, you call the 'eclipsify' ant task to copy the default settings to the new .settings folder. When you configure settings that are needed by everyone developing on the project, you merge those back into the CVS.settings folder and commit that to CVS. This way saving settings in SCM becomes a conscious process. It does require devs to merge those settings back into their .settings folders from time to time when big changes are checked in. But it's a simple system that works surprisingly well.

Stijn de Witt