IDEA - How can I place braces on the next line for .gradle files?

124 Views Asked by At

In the Code Style settings of IntelliJ IDEA, there aren't any subcategories for .gradle files (e.g., build.gradle), and under Other File Types, there isn't any option to modify brace placements. I did not find solutions on to set brace placement for .gradle files.

What I'm trying to do: Make the braces look like this by default and after reformatting:

repositories
{
    mavenCentral()
}

Instead of this:

repositories {
    mavenCentral()
}

Is this change possible using the current version of IntelliJ IDEA? (2020.1.1)

Changing the code style settings for Groovy does not have an effect for some reason.

Enter image description here

Braces for a Groovy class is placed correctly as in the settings. (This is tested in a .gradle file.)

Enter image description here

2

There are 2 best solutions below

0
On BEST ANSWER

It looks like the Settings (Preferences on macOS) → EditorCode StyleGroovyWrapping and BracesBraces placement → *Other option does not work as expected.

Please vote for the issue IDEA-241366.

4
On

.gradle files are actually Groovy files. You can check that by looking under EditorFile TypesGroovy.

As such, you can modify the code style for Groovy to move braces onto the next line by going under EditorCode StyleGroovyWrapping and Braces tab → Braces placement and tweaking it to your liking.