CheckStyle plug-in for IntelliJ IDEA
© Copyright CheckStyle-IDEA Contributors
Hosted on GitHub
A plug-in for JetBrains’ IntelliJ IDEA 2023 and 2024 which provides real-time feedback against a given
CheckStyle 9-10 profile by way of an inspection.
Please note this is not an official part of Checkstyle - they neither endorse
nor bear responsibility for this plugin. The logo is sourced from the Checkstyle resources
repository
and used under the CC BY 4.0 licence.
Released under a BSD-style licence - please see the LICENCE file for details.
Once installed, a new inspection will be available in the group ‘CheckStyle’. The ‘Inspections’ item in the preferences
panel will allow you to turn this on and to configure it.
Project exceptions are treated a little oddly. Because CheckStyle demands these to be on the current classpath, errors
will appear if these have not as yet been compiled. Further, because we cache the real-time checkers for performance
reasons, real-time scans may continue to show the errors after a compilation. A static scan will force a reload of the
Checker and should resolve this.
Configuration is available under the Settings dialogue, under Tools -> Checkstyle. This controls configuration for both the inspection and static
scanning.
The main configuration option is that of the CheckStyle file. Multiple CheckStyle file may be added, and swapped between
by using the checkbox. Files may be added using the ‘Add’ button, or you can use the versions of the standard Sun and
Google configuration that are bundled with the selected version of Checkstyle.
If you need to pass authentication information for rules file accessed via HTTP then you can use the https://user:pass@host/
form to do so.
The Scan Test Classes checkbox will enable scanning of Java files under test source roots. If disabled, these files
will be ignored.
If a custom file is being used and properties are available for definition then these will accessible using the ‘Edit
Properties’ button.
The following variables will be available if you have not otherwise overridden their values:
This tab allows you to specify any third-party checks which your configuration file makes use of. All selected
directories/JAR files will be added to CheckStyle’s classpath.
The option “Copy libraries from project directory” will tell Checkstyle-IDEA to do the following when creating custom
classloaders:
.idea
, if there is no .idea
directory,The internal classloaders will then use those copied libraries, thus preventing them from getting locked in the file
system. Since this is mainly a problem on Windows, this feature is activated by default on Windows. If you know that
all your libraries reside outside of the project (as is often the case when build tools such as Maven or Gradle are
used), then you can disable this feature. Since it slows down checker creation, you might want to keep it disabled
until necessary. After changing this option, it may be necessary to restart IDEA to see the effects.
Where you have a shared distribution it may be useful to add additional pre-bundled configurations. This can be done
by placing a JAR into the lib
directory of the plugin. The JAR should contain:
org.infernus.idea.checkstyle.csapi.BundledConfigProvider
interfaceMETA-INF/service/org.infernus.idea.checkstyle.csapi.BundledConfigProvider
that contains the fully qualified classname of the BundledConfigProvider
At present the BundledConfigProvider
interface isn’t available separately; hence you’ll need the plugin JAR to compile.
If an error occurs during the check an exception will be thrown, which IDEA will then catch and display in the standard
exceptions dialogue. If you’re unsure as to why things are awry this would be your best bet - chances are it’s a missing
property or classpath pre-requisite.
sevntu.checkstyle offers a number of useful checks written by students of the Sevastopol National Technical University
(SevNTU). They’re also kind enough to offer instructions on setting them up with this plugin.
Checkstyle Addons offers additional Checkstyle checks not found in other Checkstyle extensions, and it’s easy to
set up in Checkstyle-IDEA.
Note that the plugin has been entirely developed on OS X - while it should be fine on Linux, I’ve no idea what result
you’d get with Windows. YMMV.
The pre-requisites for the plugin are fairly light - you’ll need Git and JDK 11. Make sure your JAVA_HOME
environment variable is set correctly before invoking Gradle.
git clone https://github.com/jshiell/checkstyle-idea.git checkstyle-idea
cd checkstyle-idea
You can then easily build via Gradle:
./gradlew clean build
To run it in a sandboxed IDEA, run:
./gradlew runIde
To debug the plugin, import the plugin into IDEA as a Gradle project, and then use the runIdea
Gradle target in debug
mode.
If you’re on OS X, use IDEA with the bundled JVM. Otherwise, please ensure IDEA is running using Java 11 or later.
Jetbrains offer a support document on this
subject.
CheckStyle is unable to retrieve information on exceptions in your project until you have built it. Build your project
in IDEA and then rescan.
src/test/.+
) may not work asAny comments or bug reports are most welcome - please visit
the project website on GitHub.
The debug logging of the plugin is arcane and not particularly well done, for which I can only thank myself. However, if
such context is needed then it can be seen by using IDEA’s Help -> Debug Log Settings… and adding:
#org.infernus.idea.checkstyle
This plug-in owes its existence to both the style-overlords at work mandating compliance with a CheckStyle
configuration, and the Eclipse-CS authors for making me jealous of the real-time
scan support available for Eclipse.
Thanks to those who have contributed work and effort directly to this project:
And also thanks are due to the authors and contributors of:
And a big thank-you to everyone who’s sent me feedback or bug reports - both are much appreciated!
This code is released under a BSD licence, as specified in the accompanying LICENCE file.
Please see the changelog.