Hackdiary: Eclipse, Lombok and code formatting
I'm writing some Java at the moment. It's lot of fun. Java is fun, right?
I'm using Lombok to make Java more fun. More magic equals more fun.
And I'm using Eclipse, because, well, Lombok works well with Eclipse. I slightly prefer IntelliJ but whatever. Eclipse works fine.
Except the Eclipse code formatter which is a pain in the ass.
So, you've created a field. Let's call it name, and it's a String.
With Lombok, you write this:
Then the Eclipse formatter turns it into this.
Which is fine for some annotations that are long, but you don't need it when it is just a getter and setter annotation from Lombok.
The solution is simple:
Open your preferences
Go to Java, Code Style, Formatter.
If the active profile is "Eclipse [built-in]", click "New", and create a new profile called something like "Eclipse and Lombok"
Click 'Edit'
Go to the 'New Lines' tab
Go down to the annotations section and make sure "Insert new line after annotations on fields" is set.
Hit OK.
Reformat your code and watch your sanity be restored.














