How to force code style formatting as part of the build?

怎甘沉沦 提交于 2019-12-07 08:36:59

问题


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


回答1:


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/ 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.

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.



来源:https://stackoverflow.com/questions/7352947/how-to-force-code-style-formatting-as-part-of-the-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!