Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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/.

like image 806
Benedikt Waldvogel Avatar asked Oct 31 '22 09:10

Benedikt Waldvogel


1 Answers

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.

like image 193
Esko Avatar answered Nov 15 '22 03:11

Esko