Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google-java-format: format whole project

I'm using google-java-format to format Java code according to Google Java Style. However, I only find documentation and examples showing how to format one file using the CLI.

Is there a built-in way to format an entire Java project directly using the CLI (without looping using a shell script or something else)?

like image 312
nathaner Avatar asked Sep 01 '25 01:09

nathaner


1 Answers

The answer above suggests using xargs, so here's the command that I used:

find my_java_project/ -name "*.java" -type f -print | xargs java -jar google-java-format-1.18.1-all-deps.jar --replace

...where my current working directory contains my Java project (in the my_java_project folder) and the Google Java Format JAR.

like image 72
Chris Walker Avatar answered Sep 02 '25 15:09

Chris Walker