1

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Hykilpikonna
  • 1,749
  • 2
  • 15
  • 32

2 Answers2

2

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Andrey
  • 15,144
  • 25
  • 91
  • 187
1

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
afterburner
  • 2,552
  • 13
  • 21
  • Upvoted for your effort! But I did try changing the settings in the Groovy section, and it didn't apply to `.gradle` files for some reason... – Hykilpikonna May 19 '20 at 22:59
  • 1
    Okay, can you confirm that `*.gradle` is a registered pattern under groovy in `Editor` > `File Types`? – afterburner May 19 '20 at 23:38
  • Weird... yes `*.gradle` is included in the Groovy file type. And when I click the `4 spaces` thing on the status bar, it does lead me to the Groovy code style settings. And when I write a class in the `.gradle` file, the braces are placed correctly... – Hykilpikonna May 20 '20 at 00:12
  • 1
    Yep, so I think it's an Intellij issue. I assume, based on your screenshot, you're not using Linux, so maybe post a comment on the issue Andrey raised saying it's also happening on Linux (or whichever OS you're using) – afterburner May 20 '20 at 08:54