This article shows how to use the Google Java style guide with IntelliJ IDE. The benefit of doing this is that it will be easier for you to adhere to your organisation’s style guide by automatically highlighting deviations from it as you write code.
Step 1: Download the Checkstyle plugin
Download the latest Checkstyle plugin for IntelliJ.
- Opening IntelliJ settings varies per OS. For example, on macOS open Preferences -> Plugins.
- Select “Install plugin from disk” and browse to the file you downloaded in step 1 above and click OK.
- You should now see Checkstyle listed in the installed plugins list.
- You will need to restart IntelliJ for the plugin installation to complete.
Get the style file from Github.
- In the settings window (as in Step 2), search for “checkstyle ” in the left-hand nav search bar and select Checkstyle.
- Click the “+” button on the right-hand side of the settings window.
- Enter a description for the checks, here we used “Google Java style checks”.
- Select “Use a local Checkstyle file”.
- Browse for the style file you downloaded in step 5.
- Once the style file has been added, select the check box to the left to make the “Google Java Style” guide the default style checker.
- Click OK and you’re done.
Now you should see warnings in your code (as shown below) based on the style rules.