配置主要修改三处:
1、maven设置:https://plugins.gradle.org/m2/
2、dependencies设置:classpath "gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.8"
3、添加插件引用:apply plugin: "com.github.sherter.google-java-format"
设置截图如下
// Top-level build file where you can add configuration options common to all sub-projects/modules.
最外层的build.gradle
buildscript {
repositories {
google()
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath "gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.8"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
apply plugin: "com.github.sherter.google-java-format"
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
使用方法:在下面的截图可以看到两个任务:googleJavaFormat和verifyGoogleJavaFormat