如何强制代码样式格式化作为构建的一部分? [英] How to force code style formatting as part of the build?

查看:25
本文介绍了如何强制代码样式格式化作为构建的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法(使用ANT),可以自动重新格式化代码以遵循某些约定?

Is there a way (using ANT), it is possible to automatically reformat code to follow certain conventions?

我有几个开发人员正在开发一个程序,并且希望在提交之前保证所有类的代码格式在构建时保持一致

I have several developers working on a program and would like to guarantee that code formatting becomes consistent across all classes at build time, prior to commit

推荐答案

进行预提交的最佳方法是在源代码控制服务器上使用预提交挂钩.通过这种方式,您可以强制任何代码在不符合代码标准的情况下进入分支.

The best way to do it pre-commit is to use a pre-commit hook on your source control server. This way you can enforce that no code makes it into the branch without conforming to code standards.

http://checkstyle.sourceforge.net/ 可用作 ANT 任务或预提交钩.因此,您可以在源代码控制服务器上运行它,或者作为每个开发人员的 ANT 任务运行.但是,没有什么可以阻止您的开发人员忽略它.

http://checkstyle.sourceforge.net/ can be used as an ANT task or pre-commit hook. So you can run this on the source control server or as an ANT task for each developer. However there's nothing to stop your developer from ignoring it.

您可以通过让开发人员在分支中完成所有工作并使用集成分支来执行此后提交.您可以将代码样式检查器添加到 Jenkins 等持续集成服务器 http://jenkins-ci.org/并使用像 http://wiki.hudson-ci.org/display/这样的插件HUDSON/Sonar+plugin 报告集成分支的最新提交是否不符合标准.集成分支通过所有测试后,您将其添加到主分支.

You can do this post-commit by having developers do all their work in branches and use an integration branch. You can add a code style checker to a continuos integration server like Jenkins http://jenkins-ci.org/ and use a plugin like http://wiki.hudson-ci.org/display/HUDSON/Sonar+plugin to report if the latest commit to the integration brach doesn't live up to standards. Once the integration branch passes all tests you add it to your main branch.

这篇关于如何强制代码样式格式化作为构建的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆