在所有模块上运行android checkstyle

在所有模块上运行android checkstyle,android,module,android-gradle-plugin,checkstyle,Android,Module,Android Gradle Plugin,Checkstyle,我有一个android项目,有几个库。我想在所有源代码上运行checkstyle任务。项目结构: app (com.android.application), lib1 (com.android.library), lib2 (com.android.library), ... 我遵循了以下配置教程: 项目的构建。gradle: buildscript { repositories { google() jcenter() } dep

我有一个android项目,有几个库。我想在所有源代码上运行checkstyle任务。项目结构:

app (com.android.application),
lib1 (com.android.library),
lib2 (com.android.library),
... 
我遵循了以下配置教程:

项目的构建。gradle

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

subprojects {
    apply from: "$rootProject.projectDir/quality.gradle"

    afterEvaluate {
        check.dependsOn 'checkstyle'
    }
}
apply plugin: 'checkstyle'

checkstyle {
    toolVersion '7.4'

    configFile file("${project.rootDir}/checkstyle/checkstyle.xml")
    configProperties.checkstyleSuppressionFilterPath = file(
            "${project.rootDir}/checkstyle/suppressions.xml")
            .absolutePath
}

task checkstyle(type: Checkstyle, group: 'verification') {
    source 'src'
    include '**/*.java'
    exclude '**/gen/**'
    exclude '**/test/**'
    exclude '**/androidTest/**'
    exclude '**/R.java'
    exclude '**/BuildConfig.java'
    classpath = files()
}
质量。梯度

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

subprojects {
    apply from: "$rootProject.projectDir/quality.gradle"

    afterEvaluate {
        check.dependsOn 'checkstyle'
    }
}
apply plugin: 'checkstyle'

checkstyle {
    toolVersion '7.4'

    configFile file("${project.rootDir}/checkstyle/checkstyle.xml")
    configProperties.checkstyleSuppressionFilterPath = file(
            "${project.rootDir}/checkstyle/suppressions.xml")
            .absolutePath
}

task checkstyle(type: Checkstyle, group: 'verification') {
    source 'src'
    include '**/*.java'
    exclude '**/gen/**'
    exclude '**/test/**'
    exclude '**/androidTest/**'
    exclude '**/R.java'
    exclude '**/BuildConfig.java'
    classpath = files()
}
如果我在根项目上运行gradle检查,它只在:app modul上运行,而不是在整个项目上运行


我错过了什么?谢谢。

这可能不是您想要的答案,但我的解决方案是添加

apply from: rootProject.file("gradle/quality.gradle")
我想运行checkstyle的每个模块的build.gradle。在我的例子中,有一两个模块我不想让它运行

这是我的quality.gradle文件

apply plugin: "checkstyle"

checkstyle {
    configFile rootProject.file('checkstyle.xml')
    ignoreFailures false
    showViolations true
    toolVersion = "8.15"
}

/** Checkstyle task for new files (not in exclude list). Fail build if a check fails **/
task checkstyle(type: Checkstyle) {
    configFile rootProject.file('checkstyle/checkstyle.xml')

    //fail early
    ignoreFailures false
    showViolations true

    source 'src'
    include '**/*.java'
    exclude rootProject.file('checkstyle/checkstyle-exclude-list.txt') as String[]
    classpath = files()
}

/** Checkstyle task for legacy files. Don't fail build on errors **/
task checkstyleLegacy(type: Checkstyle) {
    configFile rootProject.file('checkstyle.xml')

    ignoreFailures true
    showViolations true

    source 'src'
    include '**/*.java'
    exclude '**/gen/**'
    classpath = files()
}

afterEvaluate {
    preBuild.dependsOn 'checkstyle'
}

谢谢,我自己设法解决了这个问题,但这个解决方案似乎对我也很好。