Tuesday, March 16, 2010

Bookmark and Share

Recently I received an IntelliJ IDEA code style settings file for Hibernate Validator, the reference implementation of JSR 303 ("Bean Validation"), to which I'm contributing.

I wanted to import it into IntelliJ in order to format any code changes I make in the project's standard style. But as it turned out, there is no functionality within the IDE for importing code style settings. Instead one has to do the following:

  • Copy the settings XML file to INTELLIJ_SETTINGS_DIR/config/codestyles (where INTELLIJ_SETTINGS_DIR is the folder containing your IntelliJ settings; typically it is situated within your home directory, the name depends on your version of IntelliJ; in my case the complete path is "~/.IdeaIC90/config/codestyles")
  • Start IntelliJ
  • Go to "File" - "Settings" - "Code Style", select "Use global settings" and choose the previously imported style from the drop-down box
  • Optionally apply the style to one project only by clicking on "Copy to Project" and selecting "Use per project settings" afterwards

4 comments:

Eric J Turley said...

In Idea 10, use File -> Export/Import settings.
Which will allow you to select/deselect from many categories of settings (including code style).

Gunnar Morling said...

Eric, that's great to know. That option wasn't available when I wrote this post. So things got definitely easier since then.

Gunnar Morling said...

For those interested: In IntelliJ 11 on Mac, the settings directory is ~/Library/Preferences/IntelliJIdea11/codestyles/.

Hyman said...

This is great!