Use IntelliJ code style in Checkstyle

Unfortunately it is not possible to do what you want for (at least) three reasons, the first two of which you have already raised:

  1. While is possible to export a code style file from Intellij IDEA using File->Settings->Code Style->Java->{Click the Settings icon}->Select Export... from the popup menu, that exported XML file only contains the changes you have made from the default settings.

  2. Those exported settings are in a format that is only meaningful to Intellij, so even if you could export every single Java code style setting to an XML file, you would then have to massively edit that file to make it meaningful to CheckStyle.

  3. Finally, note that there is an open request for Intellij to do exactly what you want. See IDEA-149529:

Current export functionality for Code Styles is lacking. Only useful for other users of IntelliJ or as a backup. Only exports the diff between user defined settings and the built-in default. This makes it very difficult to produce a matching style for other formatting/beautification tools.

It would be helpful if the export had the option of exports ALL the settings IDEA uses.

However, there is an alternative approach. Instead of providing an Intellij IDEA file to Checkstyle, provide a Checkstyle file to Intellij IDEA...

  1. Install the Checkstyle plugin, and then open two sets of one or more duplicated files in Intellij IDEA, one set configured to use IDEA's formatting and one set configured to Checkstyle's formatting.

  2. Repeatedly tweak the Checkstyle settings until its opened file(s) are formatted to conform to the corresponding files formatted by IDEA. When the sets of files match create a Checkstyle XML rules file. Tedious, but only a one time activity.

  3. Finally, you can then import your customized CheckStyle XML rules file into Intellij Idea, using Import Scheme -> CheckStyle Configuration as as shown in the screen shot below (if, and only if, you have installed the CheckStyle-IDEA plugin). This functionality did not exist when the OP was created. For more details see the following bug report: IDEA-61520 Codestyle from Checkstyle and in particular the response from JetBrains dated 2/8/16.

See also:

  • Intellij IDEA bug Configure code style from checkstyle #126

  • SO post IntelliJ IDEA code format from checkstyle configuration

Checkstyle import menu