开发者

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

Is there a way (using ANT), it is possible to automatically reformat 开发者_如何学JAVAcode 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/ 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜