Configuring Checkstyle-IDEA
-
Install the Checkstyle-IDEA plugin by going to
File→Settings(Windows/Linux), orIntelliJ IDEA→Preferences…(macOS).
SelectPlugins, pressBrowse Repository, and find the plugin.
Restart the IDE to complete the installation. -
Click
File→Settings…→Other Settings→Checkstyle. -
Set
Scan ScopetoOnly Java sources (including tests), so that the plugin will run checkstyle for our test source codes as well. -
Ensure that the
Checkstyle versionis set to8.1. Otherwise, set the correct value and clickApply. This is the same version that we are using inside Gradle, so that you won’t get any errors due to version incompatibility.
-
Click the plus sign under
Configuration File. -
Enter an arbitrary description e.g. addressbook.
-
Select
Use a local Checkstyle file. -
Use the checkstyle configuration file found at
config/checkstyle/checkstyle.xml. -
Click
Next→Finish. -
Mark
Activefor the newly imported check configuration.
-
Click
OK.
Troubleshooting Checkstyle-IDEA
Problem: When importing checkstyle.xml, Checkstyle-IDEA plugin complains that The Checkstyle rules file could not be parsed. … The file has been blacklisted for 60s.
-
Reason:
checkstyle.xmlis written for a particular version, but the plugin was not configured to the correct version. -
Solution: Ensure that you have selected the correct
Checkstyle version, that matches the version inbuild.gradle, ascheckstyle.xmlis written for Gradle’s checkstyle. ClickApplyto apply the changes before retrying the file load.
Problem: After setting up checkstyle.xml, Checkstyle-IDEA plugin does not seem to highlight the errors / real-time scanning seems broken.
-
Reason: The plugin may not immediately run after setting it up.
-
Solution: Restart the IDE.