Reputation: 553
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)?
Upvotes: 3
Views: 3053
Reputation: 1382
You can download the executable (google-java-format-[version]-all-deps.jar
) JAR from the github page and execute:
java -jar google-java-format-[version]-all-deps.jar --replace /your-project/**/*.java
This will format all your Java files directly, but the formatted support other options. If you want to see all supported options you can do:
java -jar google-java-format-[version]-all-deps.jar --help
Upvotes: 0
Reputation: 21
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.
Upvotes: 2
Reputation: 38290
After a quick read of the google-java-format documentation, it is intended to function one file at a time or on a group of files, each listed on the command line.
There appears to be plugins for intelliJ and Eclipse.
If you need to format every file in your project, you will need to do one of the following:
Upvotes: 1