简体   繁体   English

如何在开发人员之间共享Eclipse Java / XML代码样式设置?

[英]How to share eclipse Java/XML code style settings between developers?

In projects with many developers it is useful if all their IDEs are configured with identical code style settings, such that you won't get pseudo-differences due to changed formatting checked into version control whenever someone else changes your code. 在具有许多开发人员的项目中,如果所有IDE都配置有相同的代码样式设置,这将很有用,这样,只要其他人更改代码,就不会因为将更改的格式签入版本控制中而获得伪差异。 You can try to convince everybody to import project standard formatting settings, but they might forget to do that on creating a new workspace and forget to adapt them whenever a change is necessary, so this will get lost over time. 您可以尝试说服所有人导入项目标准格式设置,但他们可能会忘记在创建新工作区时执行此操作,而忘记了在需要更改时进行调整,因此随着时间的流逝,它们会丢失。

So, is there a simple way to automate things such that everybody has the same settings and gets his settings changed automatically if they need to be updated - without them taking any action on their own? 因此,是否有一种简单的方法可以使事情自动化,从而使每个人都具有相同的设置并在需要更新时自动更改其设置-无需他们自己采取任何行动?

Many of these settings are stored in .settings/org.eclipse.jdt.ui.prefs if they are configured project local , so it would be feasible to checkin this file into version control but leave out the other files in .settings. 如果将这些设置中的许多设置配置为本地项目,则它们将存储在.settings/org.eclipse.jdt.ui.prefs ,因此将这个文件检入版本控制中而将其他文件放在.settings中是可行的。 Unfortunately the formatter settings are contained in the big bucket .settings/org.eclipse.jdt.core.prefs , so you would have to do more complicated things to update these. 不幸的是,格式化程序设置包含在大存储桶.settings/org.eclipse.jdt.core.prefs ,因此您必须做更复杂的事情才能更新这些设置。 So I am wondering if there are simpler / other options. 所以我想知道是否有更简单的/其他选择。

Clarification : In my experience many developers ignore requests to adapt the various code style settings in eclipse since they consider them unimportant. 说明 :根据我的经验,许多开发人员忽略了在Eclipse中修改各种代码样式设置的请求,因为他们认为这些请求不重要。 So I want to make it at least extremely easy for them to use the project standard settings, at best the codes style adaption should work completely without their cooperation - especially on updates of the coding style. 因此,我想让他们至少非常容易地使用项目标准设置,充其量,代码风格的改编应该在没有他们合作的情况下完全可以正常工作-尤其是在更新编码风格时。 I am looking for tools to do that. 我正在寻找工具来做到这一点。

Warning: it's not a good idea to be too strict when it comes to code style. 警告:在代码风格上过于严格不是一个好主意。 Many programmers have a strong own style. 许多程序员都有很强的风格。 So be careful what you wish for. 因此,请小心您的要求。

The easiest method in Eclipse is to create an empty workspace and use that initially by simply copying it to the developer's machines. Eclipse中最简单的方法是创建一个空工作区,并通过简单地将其复制到开发人员的机器上来使用它。 You could even copy Eclipse with all the plugins. 您甚至可以复制带有所有插件的Eclipse。 This has the drawback of having to manually create changes. 这样做的缺点是必须手动创建更改。 It is also the most restrictive option. 这也是最严格的选择。

Another method is to export/import all the settings. 另一种方法是导出/导入所有设置。 This is a bit more work, but it is less restrictive. 这需要更多的工作,但是限制较少。 You would need to distribute the following settings: Formatter, Clean Up, Templates. 您将需要分发以下设置:格式化程序,清理,模板。 Furthermore you still would have to set the max. 此外,您仍然必须设置最大值。 line size in the general settings. 常规设置中的行大小。

The best way to let people adhere to code practices is to create a document about the minimum requirements. 使人们遵守代码实践的最佳方法是创建有关最低要求的文档。 Make sure you document your decissions and let people participate. 确保记录您的决定并让人们参与。 Then check if people adhere to it; 然后检查人们是否遵守它; if you let let it slip programmers will go their own way. 如果任其发展,程序员走自己的路。 Management (unfortunately) has a role to play here. 管理层(很不幸)在这里扮演着角色。

The best way of enforcing the code style is to create a CheckStyle configuration and keep it as a read only file on disk. 实施代码样式的最佳方法是创建一个CheckStyle配置,并将其保留为磁盘上的只读文件。 You can then use this as an external style sheet from the CheckStyle plugin. 然后,您可以将其用作CheckStyle插件的外部样式表。 Make sure that the Eclipse formatter and clean up settings match though. 但是,请确保Eclipse格式化程序和清除设置匹配。

The same CheckStyle configuration may be used on an automated build environment to generate warnings and errors. 可以在自动化构建环境上使用相同的CheckStyle配置来生成警告和错误。 These warnings and errors should be discussed during review. 这些警告和错误应在审核期间进行讨论。 Make sure you have loopholes, rules should ne broken if the need arises. 确保存在漏洞,如有需要,应打破规则。

Managing developers is "not unlike herding cats" 管理开发人员“与放牧猫一样”

In my old company, we would create a "default" or "template" workspace where everything is configured according to personal taste (like key settings, view positions etc.) and according to the companies rules (formatter, compiler warnings, checkstyle, mandatory plugins etc.). 在我以前的公司中,我们将创建一个“默认”或“模板”工作区,其中的所有内容均根据个人喜好(例如键设置,视图位置等) 根据公司规则(格式程序,编译器警告,checkstyle,强制性)进行配置插件等)。

Every time I needed a new workspace, I just duplicated this template workspace. 每当我需要一个新的工作区时,我都会复制此模板工作区。

Since starting from scratch with a new workplace is such a pain, people automatically got used to using the template, rather than creating a complete new workspace. 由于从头开始创建新的工作场所非常痛苦,因此人们会自动习惯于使用模板,而不是创建一个完整的新工作空间。 So there was never a problem with people forgetting it. 因此,人们永远不会忘记它。

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

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