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

1

4

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

Rapscallion answered 8/9, 2011 at 18:44 Comment(1)
If you must have any automated formatting rules, prefer check-in time to build-time. The latter would lead to additional merge costs and check-in noise.Punak
R
5

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.

Reconnaissance answered 8/9, 2011 at 18:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.