Configuring Google Style Guide for Java for IntelliJ

Reed Odeneal
Nov 12, 2020 · 4 min read
Image for post
Image for post

A case for style guides

Tabs or spaces? Single or double quotes? As a developer, your time is more wisely spent learning and knowing about what the code is doing, not trying to figure out idiosyncrasies of how the previous engineer (or you, six+ months ago) liked to style things. Enter: a style guide.

Automating your style

You can take your style guide implementation a step further and automate your checks in your IDE. You’ll gain the benefit of making it easier to adhere to your team’s accepted style guide by automatically highlighting deviations from the guide as you write code. Most IDEs support the enforcement of a style guide with automated checks and refactoring features. Here we’re going to look at how to configure JetBrains IntelliJ for Google Style Guide for Java.

Image for post
Image for post
Settings > Preferences… > Editor > Code Style > Java
Image for post
Image for post

Applying the Google Style Guide in your Java code

Now that you have imported the style guide to IntelliJ you can take advantage of the Code function menu and apply the style guide to your code. You have the option of reformatting an entire package/folder by selecting the package from the navigation menu, the currently open .java file, or a selection of code from within the currently open file by highlighting the code you wish to reformat. Select Code > Reformat Code.

Image for post
Image for post

Conclusion

A style guide is a set of standards that development teams can implement to ensure consistency across projects for how code should be formatted and organized. Many languages maintain official guides while most others have widely accepted standards such as Google Style Guide for Java. Leveraging IntelliJ’s Code Style feature you can import and automatically enforce Google Java Style Guide as you write your code. Letting your IDE work for you frees you up to think more about solving problems and debugging instead of worrying about formatting.

The Startup

Medium's largest active publication, followed by +771K people. Follow to join our community.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store