Code formatting upon building a module

Could anyone point me to a working configuration that would format the Java code of a module upon building? Especially something that would clear the horrendous problem of the space indents vs tab indents.

I have added this to Attachments’s POM, and while it does perform some formatting, it doesn’t prevent well intended PRs to look like a mess…

Does the mess still happen even after formatting the entire module and do a formatting commit first?

cc @teleivo

And how do you do that, just through running one build with the Maven plugin in question?

Yes! :slight_smile:

That doesn’t quite solve the tab indents vs space indents mess. I mean it doesn’t solve it at all. Unless I’m missing something.

Is this of any help? Enforce checkstyle for modules

We can add an execution goal to make it format upon building.

It can be manually run by:

mvn java-formatter:format

Thanks @gayanw, you gave me some good inspiration here :slight_smile:

However I also wanted to format other files than .java files, so I went for another plugin (still using OpenMRSFormatter.xml though) and I bound it to the compile phase so that the formatting always happens for whoever builds the module, which should always happen prior to making a PR.

I just did a formatting commit on ‘Attachments’ here. Let’s see how this goes with upcoming PRs…

Cc @oslynn