score:174

Accepted answer

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 they 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 to 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 remove your detailed launch parameters!)

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

should be in your scm (especially .project and .classpath according to the eclipse documentation).

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

score:1

i have spent too many hours configuring eclipse workspace settings for new colleagues (and myself). what i ended up doing eventually was copying my own .metadata to the new developer machine.

if you are working on a team, then i think the following are very good candidates to keep under version control:

  • installed jres and their names
  • server runtime environments
  • java editor templates
  • version control keyboard shortcuts
  • plugin settings that do not provide project specific settings
  • maven settings
  • preconfigured perspectives
  • ...

score:1

i haven't tried to put anything in .metadata under version control, but i'm using version control for these files for ten years now:

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

the main reason is that eclipse sometimes damages those files. without version control, you will get weird and hard to track errors. with version control, you can immediately see "why is it trying to deploy test classes???" or "why is maven and eclipse using the same classpath?" (leading to https://bugs.eclipse.org/bugs/show_bug.cgi?id=430605).

with version control, you can see when it happens and easily go back to a working set of config files.

if you use m2e: you can import the project now with the fast "import existing project" instead of the slow "import maven project".

the drawback of this approach is that eclipse seems to randomly change some of those files. most plugins keep them stable but some use hashmap instead of, say, linkedhashmap so the order of elements changes all the time. this means there is an additional step when you commit: check for any modified settings and handle them, first.

it also means that the whole team has to agree on some standards: like which warnings should be enabled. it's interesting that many people see this as a additional problem - as if they weren't working together.

in my experience, it takes a couple of weeks until those files stabilize. partly because you gradually learn how to tweak eclipse, partly because people learn what not to touch. you can think of this as lost time or time spent to improve the quality of your work environment (like keeping your desk uncluttered).

there is a bonus advantage of the "commit settings first": it gets people to commit more often and in smaller pieces (i.e. more like "one thought at a time" instead of "on feature at a time plus a thousand of other, unrelated things that i just happened to stumble upton ... what was i working on again?").

as a seasoned developer, i've come to prefer the "small commits" way of working; it's just easier to stay on track and you tend to sort your thoughts and changes into smaller, more manageable steps. this helps to reduce the level of complexity. everyone can juggle with one ball, no one can juggle with 20.

ps: for certain setting files, i have unit tests to make sure known errors don't creep in like the "trying to deploy tests" in wtp. that helps in the initial phase "commit everything, i'm too busy" phase.

score:2

consider:

.classpath
.project
.launch

these should be in version control as long as you stick to using project-relative paths. this allows other developers to check out the project and start working right away without having to go through all the setup pain that other developers went through as well.

you might be tempted to include .metadata in version control as well so eclipse developers can check out an entire workspace and have it preconfigured with all the right projects, but it includes a lot of user specific information that anytime anybody works on it, it will change, so i would advise to not include .metadata. it's easy to build a local workspace just by importing all existing eclipse projects.

score:4

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?

score:6

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.

score:7

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.

score:14

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 sharing cdt-project files in repository always causes conflicts.

score:19

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.


Related Query

More Query from same tag