Google-java-format-gradle-plugin integrates with Gradle, but how can I run it automatically as part of the normal build?
How can I automatically run google-java-format as part of my Gradle build?
1.5k Views Asked by Bob Lee At
2
There are 2 best solutions below
0

Sherter gradle plugin is automatically integrated to "gradle build". When you run it, it will run "gradle verifyGoogleJavaFormat". In case of violations, the build will fail.
We are using it on jenkins and it works. You will only need dependency to build.gradle file:
compile group: 'com.github.sherter.google-java-format', name: 'com.github.sherter.google-java-format.gradle.plugin', version: '0.8', ext: 'pom'
And also add plugin:
id 'com.github.sherter.google-java-format' version '0.8'
Then just run "gradle build" and you can see in the console, that verifyGoogleJavaFormat was executed.
DependsOn plugin's task that you need from a task that relates to a normal build, for example, you can use
preBuild
task:or shorter
Also you can choose another task instead of
preBuild
.