Benedikt Waldvogel
Benedikt Waldvogel

Reputation: 12866

Configure IntelliJ code style with Gradle

Is there a way to configure the project-specific Java code style and import rules in IntelliJ with a Gradle task?

In Eclipse it is possible by copying org.eclipse.jdt.core.prefs and org.eclipse.jdt.ui.prefs to $PROJECT/.settings/.

Upvotes: 7

Views: 3548

Answers (1)

Esko
Esko

Reputation: 29367

Use EditorConfig. It's cross platform/IDE/tool and IDEA has native support for it so it pretty much does what you want in less destructive way.

For example all my projects have the following .editorconfig file:

# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# all-encompassing default settings unless otherwise specified
[*]
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true

For actual code style conventions, I recommend human eye. Code style is social, not technical problem. If, however, you run some really obscure and specific formatting ruleset, you should look into IntelliJ IDEA help: Exporting and Importing Settings for sharing the formatting configurations between devs.

Upvotes: 4

Related Questions