Configure Google Java Code Style in IntelliJ
Configuring Google Java Code Style in IntelliJ IDEA
-
Download the XML Style File:
Download the Google code style XML file for IntelliJ from the official repository: https://github.com/google/styleguide. Look for the
intellij-java-google-style.xml
file. -
Open IntelliJ IDEA:
Start IntelliJ IDEA and open your project.
-
Import the XML Style File:
- Go to
File
>Settings
(orIntelliJ IDEA
>Preferences
on macOS). - On the left sidebar, expand
Editor
and selectCode Style
. - On the top right, click on the gear icon (⚙️) and choose
Import Scheme
>IntelliJ IDEA code style XML
. - Navigate and select the
intellij-java-google-style.xml
file you downloaded earlier.
- Go to
-
Apply the Google Code Style:
Once you’ve imported the scheme, it should appear in the dropdown list of available schemes. Simply select it to apply Google’s code style to your project.
-
Reformat Code:
If you wish to reformat your existing code according to Google’s style:
- Select the code or files you wish to reformat.
- Right-click and choose
Reformat Code
or use the keyboard shortcut (by defaultCtrl+Alt+L
on Windows/Linux orCmd+Option+L
on macOS).
-
Save and Close:
Click
OK
to save and close the settings window.
Note: If you’re working on a team, it’s a good practice to ensure everyone is using the same code style for consistency throughout the codebase.