Checkstyle

Checkstyle

Checkstyle is a tool in the open source community which helps to ensure that the java code is following the standards that you are recommending. In checkstyle you can customize rules that will help you to address certain coding standards

Setting up checkstyle

The installation details can be obtained from the sourceforge.net/update

You can use Eclipse Update Manager to update the Checkstyle or any related plugins. Please see Eclipse Update Manager

If the IDE that you use is Eclipse, you need to select the Sun Checks which is at Window -> Preferences -> Checkstyle.

After selecting the required on, click the “Set as Default”.

Setting up checkstyle
Setting up checkstyle

Configuring Checkstyle

When you are changing the setting from the standard profile it’s better to make a copy of  the existing profile.

You can keep a copy of the existing by selecting as shown below.

Configuring Checkstyle
Configuring Checkstyle

For the new configuration, select configure.

Configuring Checkstyle
Configuring Checkstyle

You can use this as the default one.

Checkstyle for Teams

When you have a team involved in development it’s better to for same rules for the coding style.

The Eclipse checkstyle plugin  caters to this  by providing a remote site for the checkstyle settings.

Click in the new in the settings and select ‘Remote Configuration’.

Provide the  ruleset a description and provide the  URL that can be used for this settings.

Checkstyle Check Configuration
Checkstyle Check Configuration

You can use this setting as the default one.

Checkstyle for Projects

You can use the new profile created as the default one.

In order to have the Checkstyle active for the project you need to activate the Eclipse Checkstyle Plugin for the project.

Right click the project and search for Checkstyle. Select the checkbox “Checkstyle active for this project”.

Checkstyle for Project
Checkstyle for Project

Once this is done the Checkstyle browser view can be used to display the violations.

Checkstyle Browser
Checkstyle Browser

More on Checkstyle at www.checkstyle.sourceforge.net