Skip to content

Checkstyle

Jakub Żuchowski edited this page Apr 15, 2024 · 2 revisions

Are you a backend developer frequently facing checkstyle errors during commits? This guide will show you how to configure IntelliJ IDEA to automatically correct many of these errors using the CheckStyle-IDEA plugin.

How to Configure IntelliJ for Checkstyle Automation

Step 1: Install CheckStyle-IDEA plugin

Install the plugin from the IntelliJ plugin marketplace to integrate Checkstyle into your IDE.

Plugin install

Step 2: Configure the Plugin with Your Checkstyle Configuration

Navigate to Settings -> Tools -> Checkstyle. Click the plus (+) icon in Configuration file section and select Use a local Checkstyle file. Locate your configuration file at PROJECT_DIR/config/checkstyle/checkstyle.xml. Enable the configuration by checking the box next to the newly added file.

Checkstyle setting window

Step 3: Set Up IntelliJ Code Style to Match Checkstyle

Access Settings -> Editor -> Code Style. Click the gear icon (⚙️) next to Scheme, then select Import Scheme -> Checkstyle Configuration.

Code Style settings window

Utilizing the Configuration

During development, regularly use Code -> Reformat Code and Code -> Optimize Imports from the IntelliJ IDEA menu. These features will automatically adjust your code to meet most of the Checkstyle rules. Manual adjustments might still be necessary for some specific cases.

Clone this wiki locally