revelc / formatter-maven-plugin

Formatter Maven Plugin
https://code.revelc.net/formatter-maven-plugin
Apache License 2.0
284 stars 90 forks source link

Show diff when `has not been previously formatted` is reported #937

Open sebthom opened 1 week ago

sebthom commented 1 week ago

Is your feature request related to a problem? Please describe.

First thanks for this great maven plugin! I have a project where the builds break with

org.apache.maven.plugin.MojoFailureException: File '.../xyz.java' has not been previously formatted. Please format file (for example by invoking `mvn net.revelc.code.formatter:formatter-maven-plugin:2.24.1:format`) and commit before running validation!

However I formatted the source code using the same config with the formatter plugin. So I have no idea what is going wrong.

Describe the solution you'd like Please add an option to output a diff between the supposedly unformatted file and what the formatter thinks the formatted file should look like. This can help tracking down the underlying issue, may it be a bug in the formatter, with the line encoding, etc.

E.g. using https://github.com/java-diff-utils/java-diff-utils

So we get something like this https://github.com/diffplug/spotless?tab=readme-ov-file#%EF%B8%8F-spotless-for-maven

hazendaz commented 5 days ago

Hi @sebthom, is this something you would be willing to provide support for here? It would happen quicker if you could contribute such an update.

As to the issue you are facing, can you provide a small reproducible project that shows this behavior so we can easily take a look to see. Add instructions to it on how you ran it to confirm.

Also keep in mind, add version you used here, platform you are on, etc. Anything that can help with diagnosing the issue.