简体   繁体   English

要签入还是不签入整个Eclipse项目?

[英]To check in, or not check in, the entire Eclipse project?

I'm soon going to check in the very first commit of a new Java project. 我很快就会检查新Java项目的第一次提交。 I work with Eclipse Ganymede and a bunch of plug ins are making things a little bit easier. 我使用Eclipse Ganymede,一堆插件让事情变得更容易一些。

Previously I've been part of projects where the entire Eclipse project was checked in. It's quite convenient to get the project settings after a check out. 以前我一直参与检查整个Eclipse项目的项目。在结账后获取项目设置非常方便。 However this approach still was not problem free: 然而,这种方法仍然没有问题:

  • I strongly suspect that some Eclipse configuration files would change without user interaction (from when I used Eclipse Europa), making them appear as changed (as they were changed, but not interactively) when it's time to do a commit. 我强烈怀疑某些Eclipse配置文件会在没有用户交互的情况下发生变化(从我使用Eclipse Europa时开始),使得它们在进行提交时显示为已更改(因为它们已更改,但不是交互式)。
  • There are settings unique to each development machine as well as settings global for all developers on a project. 每个开发机器都有独特的设置,以及项目中所有开发人员的全局设置。 Keeping these apart was hard. 保持这些分离很难。
  • Sometime if the Eclipse version was different from others Eclipse would get angry and mess up the project configuration. 有时,如果Eclipse版本与其他版本不同,Eclipse会生气并弄乱项目配置。 Another case is that it change the format so it gets updated, and if commited messes up the configuration for others. 另一种情况是它更改格式以便更新,如果提交则会混淆其他人的配置。

For this specific project I have another reason not to commit the project files: 对于这个特定项目,我有另一个原因不提交项目文件:

  • There might be developers who prefer NetBeans which will join the project later. 可能有开发人员喜欢NetBeans,以后会加入该项目。 However they won't join within the coming months. 但是他们不会在未来几个月内加入。

How do you organize this? 你是如何组织这个的? What do you check into versioning control and what do you keep outside? 你如何检查版本控制以及你在外面做什么? What do you consider best practice in this kind of situation? 在这种情况下,您认为最佳做法是什么?

At a minimum you should be check-in the .project and .classpath files. 您至少应该签入.project.classpath文件。 If anybody on your team is hard-coding an external JAR location in the .classpath you should put them up against the wall and shoot them. 如果团队中的任何人正在对.classpath的外部JAR位置进行硬编码,则应将它们靠墙放置并拍摄它们。 I use Maven to manage my dependencies but if you are not using maven you should create user libraries for your external JARs with with a consistent naming convention. 我使用Maven来管理我的依赖项,但是如果你不使用maven,你应该使用一致的命名约定为外部JAR创建用户库。

After that you need to consider things on a plug-in by plug-in basis. 之后,您需要通过插件来考虑插件上的内容。 For example I work with Spring so I always check-in the .springBeans and likewise for CheckStyle I always check-in the .checkstyle project. 例如,我使用Spring,所以我总是签入.springBeans ,同样对于CheckStyle,我总是签入.checkstyle项目。

It gets a bit trickier when it comes to the configuration in the .settings folder but I generally check-in the following if I change the default settings for my project and want them shared with the rest of the team: 当涉及到.settings文件夹中的配置时,它会变得有点棘手,但如果我更改项目的默认设置并希望它们与团队的其他成员共享,我通常.settings入以下内容:

  • .settings/org.eclipse.jdt.ui.prefs - it contains the settings for the import ordering .settings / org.eclipse.jdt.ui.prefs - 它包含导入排序的设置
  • .settings/org.eclipse.jdt.core.prefs - it contains the settings for the compiler version .settings / org.eclipse.jdt.core.prefs - 它包含编译器版本的设置

In general I haven't noticed Ganymede modifying files without me modifying the project preferences. 一般来说,我没有注意到Ganymede在没有修改项目首选项的情况下修改文件。

I recommend to use maven so that the entire life cycle is outside of any IDE. 我建议使用maven,以便整个生命周期都在任何IDE之外。 You can easily create an eclipse project with it on the command line and you can use whatever you want, if it's not eclipse. 您可以在命令行上使用它轻松创建一个eclipse项目,如果它不是eclipse,您可以使用任何您想要的东西。 It has it's quirks but takes out a lot of bitterness when it comes to dependencies and build management. 它有它的怪癖,但在涉及依赖和构建管理时会带来很多苦涩。

In our world, we check in the entire Eclipse project and the entire parallel but separate Netbeans project. 在我们的世界中,我们检查整个Eclipse项目和整个并行但独立的Netbeans项目。 Our motivations for this were entirely focused on "when I do a checkout, I want a functional configuration immediately afterward." 我们对此的动机完全集中在“当我结帐时,我希望在之后立即进行功能配置。” This means that we had to do some work: 这意味着我们必须做一些工作:

  1. Create runnable configurations for each primary IDE (people like what they like). 为每个主IDE(人们喜欢他们喜欢的东西)创建可运行的配置。 This includes main class, working directory, VM parameters, etc. 这包括主类,工作目录,VM参数等。
  2. Create useful start up scripts for all of our relevant scenarios. 为我们所有相关方案创建有用的启动脚本。
  3. Create edited datasets that don't cause the checkout to take too much longer (it's a big project). 创建不会导致结账时间过长的编辑数据集(这是一个大项目)。

This philosophy was worth cash money (or at least labor hours which are almost more valuable) when our new hire was able to check out the project from Subversion into Eclipse and immediately run a functional system with a (small) real data set without any fuss or bother on his part. 当我们的新员工能够从Subversion检查项目到Eclipse并立即运行具有(小)实际数据集的功能系统时,这种理念值得现金(或至少劳动时间几乎更有价值)或者打扰他自己。

Follow up : this philosophy of "make the new guy's life easier" paid off again when he changed IDEs (he decided to try Netbeans after using Eclipse for quite a long time and decided to stick with it for a while). 跟进 :当他改变IDE时,这种“让新人生活更轻松”的理念得到了回报(他决定在使用Eclipse很长一段时间后尝试使用Netbeans并决定坚持使用它一段时间)。 No configuration was required at all, he just opened the Netbeans project in the same directory that Eclipse had been pointing to. 根本不需要配置,他只是在Eclipse指向的同一目录中打开了Netbeans项目。 Elapsed switchover time: approximately 60 seconds. 经过的切换时间:大约60秒。

I only ever check in things are done by humans, anything else that is generated (whether automaticly or not) should be easy to regenerate again and is liable to change (as you've stated). 我只检查事情是由人类完成的,任何其他产生的东西(无论是否自动)都应该很容易再生,并且容易改变(如你所说)。 The only exeption to this is when the generated files are hard (requires alot of human intervention ;) ) to get it right. 对此的唯一要求是生成的文件很难(需要很多人为干预;))才能使其正确。 How ever things like this should really be automated some how. 这样的事情应该如何真正实现自动化。

Try to port your project to a build system like maven. 尝试将项目移植到像maven这样的构建系统。 It has everything you need to get the same experience of the project on every machine you use. 它拥有您在所使用的每台机器上获得相同项目体验所需的一切。

There are plugins for just everything. 只有一切插件。 Like the eclipse plugin. 就像eclipse插件一样。 You just type "mvn eclipse:eclipse" and the plugin generates your entire ready to work eclipse project. 你只需输入“mvn eclipse:eclipse”,插件就可以生成你准备工作的整个eclipse项目。

To give the answer to your question. 给出你的问题的答案。 Never check in files that are not being used by your project at any time in the development cycle. 切勿在开发周期中随时签入项目未使用的文件。 That means that metadata files like eclipse properties etc. should never be checked in in a SCM. 这意味着不应该在SCM中签入像eclipse属性等元数据文件。

I like checking in the .project, .classpath, and similar files only if they will be identical on any Eclipse user's machine anyway. 我喜欢检查.project,.classpath和类似文件, 只要它们在任何Eclipse用户的机器上都是相同的。 (People using other IDEs should be able to check out and build your project regardless, but that issue is orthogonal to whether or not to check in Eclipse-only files.) (使用其他IDE的人应该能够检查并构建您的项目,但这个问题与是否检查仅Eclipse文件是正交的。)

If different users working on the project will want to make changes or tweaks to their .project or .classpath or other files, I recommend that you do not check them into source control. 如果处理项目的不同用户想要对他们的.project或.classpath或其他文件进行更改或调整,我建议您不要将它们检查到源代码管理中。 It will only cause headaches in the long run. 从长远来看,这只会引起头痛。

I use IntelliJ, which has XML project files. 我使用IntelliJ,它有XML项目文件。 I don't check those in, because they change frequently and are easy to recreate if I need to. 我不会检查它们,因为它们经常更改,并且如果需要,很容易重新创建。

I don't check in JAR files. 我不签入JAR文件。 I keep those in a separate repository, a la Maven 2. 我将它们保存在一个单独的存储库中,即la Maven 2。

I don't check in WARs or JARs or javadocs or anything else that can be generated. 我不检查WAR,JAR或javadoc或其他任何可以生成的内容。

I do check in SQL and scripts and Java source and XML config. 我会检查SQL和脚本以及Java源代码和XML配置。

I'd suggest having the actual project files ignored by the version control system due to the downsides you mentioned. 由于你提到的缺点,我建议让版本控制系统忽略实际的项目文件。

If there is enough consistent information in the project settings that there would be benefit from having it accessible, copy it to a location that Eclipse doesn't treat as special, and you'll have it available to work with on checkout (and copy back to where Eclipse will pay attention to it). 如果项目设置中有足够的一致信息可以使其可访问,请将其复制到Eclipse不认为特殊的位置,并且您可以在结帐时使用它(并复制回来)到Eclipse会注意它的地方)。 There is a decent chance that keeping the actual project files separate from the controlled ones will result in loss of synch, so I'd only suggest this if there is clear benefit from having the settings available (or you're confident that you'll be able to keep them synchronised) 保持实际项目文件与受控项目文件分离的可能性很大,会导致同步丢失,所以我只建议如果有可用的设置有明显的好处(或者你有信心你会能够保持同步)

In our case, we used to check in the project files (.project and .classpath) to make it easy for all developers to create their project workspace. 在我们的例子中,我们用来检查项目文件(.project和.classpath),以便所有开发人员都可以轻松创建项目工作区。 A common preferences file and team project set were located in source control as well, so creating your workspace was as simple as import preferences and import team project set. 公共首选项文件和团队项目集也位于源代码管理中,因此创建工作区就像导入首选项和导入团队项目集一样简单。 This worked very well, but does rely on everyone having a consistent environment, any customizations would have to be applied after the basic workspace is created. 这非常有效,但确实依赖于具有一致环境的每个人,在创建基本工作空间之后必须应用任何自定义。

We still do this for the most part, but Maven is now used so of course dependency management is handled via Maven instead. 我们仍然在大多数情况下这样做,但现在使用Maven,因此依赖管理通过Maven来处理。 To avoid conflicting information, the .project and .classpath were removed from source control and are now generated via maven goals before we import the team project set. 为了避免冲突信息,.project和.classpath已从源代码管理中删除,现在在导入团队项目集之前通过maven目标生成。 This would easily allow for different environments, as you would simply need scripts to generate the IDE specific portions based on the Maven configuration. 这很容易允许不同的环境,因为您只需要脚本来根据Maven配置生成IDE特定部分。

PS-For ease of maintenance though, I prefer having everyone use the same environment. PS-为了便于维护,我更喜欢让每个人都使用相同的环境。 Anything else inevitably becomes a full time maintenance job for someone. 其他任何东西都不可避免地成为某人的全职维护工作。

Netbeans 6.5有一个改进的Eclipse项目导入,它应该将Netbeans的变化同步回Eclipse: http//wiki.netbeans.org/NewAndNoteWorthyNB65#section-NewAndNoteWorthyNB65-EclipseProjectImportAndSynchronization

Don't. 别。 Only check in the source code of your projects. 只检查项目的源代码。

As a response to: 作为回应:

"There are settings unique to each development machine as well as settings global for all developers on a project. Keeping these apart was hard." “每个开发机器都有独特的设置,以及项目中所有开发人员的全局设置。保持这些区分很难。”

Eclipse offers a number of ways to keep local settings manageable: Java Classpath Variables (Java > Build Path > Classpath Variables) are one, 'Linked Resources' (General > Workspace > Linked Resources) are another http://help.eclipse.org/stable/index.jsp?topic=/org.eclipse.platform.doc.user/concepts/concepts-13.htm Creating a README that states which settings to set before building/running the project works pretty well in my opinion. Eclipse提供了许多方法来保持本地设置的可管理性:Java类路径变量(Java>构建路径>类路径变量)是一个,“链接资源”(常规>工作空间>链接资源)是另一个http://help.eclipse.org /stable/index.jsp?topic=/org.eclipse.platform.doc.user/concepts/concepts-13.htm在我看来,创建一个自述文件,说明在构建/运行项目之前要设置的设置。

Now how to make sure your continuous build system understands the changes that were made to the eclipse settings, thats another issue... (I have a separate build.xml for ant that I keep up to date by hand) 现在,如何确保您的连续构建系统了解对eclipse设置所做的更改,这是另一个问题...(我有一个单独的build.xml for ant,我手动更新)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM