Use the -i or --replace argument to format the files by re-writing instead of printing the changes to stdout:
npx google-java-format -i --glob=folder/**/*.java
Dry-run
To just check files use the -n (or --dry-run) parameter:
npx google-java-format -n --glob=folder/**/*.java
Integrations
Pre-commit
May be wrapped in git pre-commit if desired, there are examples on line demonstrating this
If you would like to contribute a pre-commit hook, perhaps one that is Husky-compatible, that would be great! Open a PR with the hook and remove this comment :-)
Github Actions
May be used in GitHub Actions workflows to verify PRs meet formatting standards,
as done in Invertasereact-native-firebase, specifically this package.json run script is called in a CI job and sets exit status correctly to fail the job if there are formatting inconsistencies found: