How to configure spotless to keep line breaks for java builders

427 Views Asked by At

I am using spotless to format my java code and I am fairly happy with it. However it keeps reformatting my builders so that everything is on one line when it is within the line limits.

For example this

final var user = User.builder()
    .id(1L)
    .name("name")
    .build();

becomes this

final var user = 
    User.builder().id(1L).name("name").build();

I know that I can turn off spotless for certain snippets by using spotless:off/on, however we are using builders so extensively that this would escalate into a tedious task fairly quickly.

So is there a way to force spotless to keep line breaks for these builders?

EDIT I noticed i have the samte problem for longer assertThat statements:

assertThat(result.getContacts())
    .hasSize(2)
    .contains(newContact)
    .contains(contactToUpdate);

becomes this

assertThat(result.getContacts()).hasSize(2).contains(newContact).contains(contactToUpdate);
0

There are 0 best solutions below