jenkins the definitive guide

(Jeff_L) #1

Figure 9.1. It is easy to configure Checkstyle rules in Eclipse


Configuring Checkstyle in your build is usually straightforward. If you are using Ant, you need to
download the checkstyle JAR file from the website^2 and make it available to Ant. You could place it
in your Ant lib directory, but this would mean customizing the Ant installation on your build server
(and any slave nodes), so it is not a very portable solution. A better approach would be to place the
Checkstyle JAR file in one of your project directories, or to use Ivy or the Maven Ant Task library
to declare a dependency on Checkstyle. If you opt for keeping the Checkstyle JAR file in the project
directories, you could declare the Checkstyle task as shown here:


<taskdef resource="checkstyletask.properties"
classpath="lib/checkstyle-5.3-all.jar"/>

Then, to generate Checkstyle reports in an XML format that Jenkins can use, you could do the following:


<target name="checkstyle">
<checkstyle config="src/main/config/company-checks.xml">
<fileset dir="src/main/java" includes="**/*.java"/>
<formatter type="plain"/>
<formatter type="xml"/>
</checkstyle>
</target>

Now, just invoke this task (e.g., ant checkstyle) to generate the Checkstyle reports.


(^2) http://checkstyle.sourceforge.net

Free download pdf