Checkstyle is a source code analyzer tool to help Java developers write Java source code that adheres to a Java coding standard. The tool is licensed under the GNU LGPL license. (Lesser General Public License)
Checkstyle inspects the Java source code and reports the violations of a defined set of coding rules. It automates the process of checking Java source code and enforcing a coding standard into Java projects.
Consistent coding practices are a must for Java projects that involve more than one developer. Source code that conforms to a coding standard is more readable and maintainable.
Java coding standards
The tool support two popular coding standards:
- Sun’s coding conventions
- Google’s coding convention
Having said that, Checkstyle is highly configurable and can be made to support any defined coding standard.
Install Checkstyle Eclipse Plugin
Launch Eclipse IDE.
Choose Help ->> Eclipse Marketplace… menu option.
Search for Checkstyle in the Find box.
Click on the Install button.
Follow the instructions in the install wizard screen.
To activate the tool on the project in the IDE, right-click on the project
Right click>> Checkstyle >> Activate Checkstyle.
Maven Checkstyle plugin
We can use the Maven Checkstyle plugin, to integrate the tool into the build process of the Java project. Add the plugin to the pom.xml file of the project.