java_format_check
This script will check if the formatting of the *.java
files in the given directory ($PWD
if not given) and its subdirectories adhere to the Google Java Style.
This script’s exit code is 0
if all *.java
files adhere to Google Java Style or 1
if not.
The following parameters are optional:
v
-
display the paths of the files whose formatting does not adhere to Google Java Style
Both |
This script needs internet access if it does not find the cached JAR file. It will download and cache the google-java-format JAR. The JAR is cached in the following location (in order of preference):
|
If you are using Gradle or Maven you might want to use Spotless instead of this script:
If you are using a JetBrains IDE you might want to use the google-java-format plugin. |
Usage
$ scripts/java/java_format_check.sh
$ scripts/java/java_format_check.sh /tmp/example/src/main/java
$ echo $?
1
$ scripts/java/java_format_check.sh -v /tmp/example/src/main/java
/tmp/example/src/main/java/Example.java
$ echo $?
1
$ scripts/java/java_format.sh /tmp/example/src/main/java
$ scripts/java/java_format_check.sh /tmp/example/src/main/java
$ echo $?
0