Using Checkstyle with ANT for JAVA Code review

Hi All,

Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. It automates the process of checking Java code to spare humans of this boring (but important) task. This makes it ideal for projects that want to enforce a coding standard.

Step 1: Download Checkstyle jar from

Step 2: Place the checkstyle jars into the Lib directory of your project.

Step 3: Write a build script and add the below ANT Task for running Checkstyle code reviews. Initially Checkstyle generates a XML report for code reviews. So we can use XSL Stylesheet to transform that in HTML format.(see inside the task)

<target name=”runCodeReview”>

config = “${basedir}/lib/checkstyle_allchecks.xml” classpathref=”build.classpath”  failOnViolation=”false” >
<fileset dir=”${basedir}/src” includes=”**/*.java”/>
<!– fromatter is used to generate a XML file –>

<xslt in=”${basedir}/reports/code-cs.xml” out=”${basedir}/reports/java_checkstyle_report.html”     style=”${basedir}/checkstyle.xsl”/>
<!– we can use XSL stylesheet to transform the XML reports into HTML format –>

NOTE: Sometime it is not feasible to use all the JLS coding standards, due to project coding standards requirement, For this we can easily customize few rules in checkstyle_allchecks.xml.

R Vashi


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s