Allow me to share a personal experience about enforcing rules around styles and formats.
Not long ago, I had to compare and merge a forked code (2 lanes) with more than 1 year of changes in each lane. Lanes were being developed by two different teams, from different companies. Two teams that never minded coordinating with each other.
I estimated the task in one month and a half (full time), several meetings with both teams and migrating both lanes to a single repository (one team was working with Subversion, the other with Gitlab). In consequence, the release of the version had to be delayed by two months (at least). To make it even more fun, I had to do the job so that both teams could keep working on their respective lanes.
The customer was so pissed at this, that it couldn't but bought my suggestion about establishing corporative code styles, formats and tools. Because these things could help to reduce the complexity of the task and avoid similar scenarios in the future.
Formatting the code removed more than half of the changes. Took me 1 month (full time) and 2 meetings (8h) with both teams. Despite these things, there were so many differences that I had to do it manually with Meld and Eclipse.
Contrary to what Ewan's answer suggest, enforcing styles and formats (among other things) is convenient. It's something to consider before writing any line of code and everybody must agree, no matter personal preferences or likes. The context matters, the project's need for code management dictates whether we must enforce these practices or not. If you are accountable, yours is the choice and the responsibility so the team have to accept it.
Developers on their own, can not impose personal preferences over the needs of the project for code management. The project's dictates, the accountable decide, the responsible ensures and everybody executes. As professionals we are, we have to be capable of adapting ourselves to the circumstances.
Ok, how to do it?
The simpler way is from the package manager. Gradle, Maven, Ivy, etc. This way the style and format policies are managed alongside the source code they serve. Additionally, make it executable in different contexts (CI pipelines)
Is there a way to do basic formatting from the command line
Yes. Maven and Gradle plugins usually wrap libraries that do the job. You could simply download the lib and use it as an external tool. However, you will find the integration with the package manager to be more convenient and simpler to use.
You could also make a shell script to execute the plugin. Not sure about Gradle or Ivy, but Maven allows specific goals executions. For example:
#formatter-maven-plugin
$ mvn formatter:format