运行 android 所有模块的 checkstyle

Run android checkstyle on all modules

我有一个包含多个库的 android 项目。我想 运行 对所有源代码执行检查样式任务。项目结构:

app (com.android.application),
lib1 (com.android.library),
lib2 (com.android.library),
... 

我遵循了这个配置教程:

https://github.com/Piasy/AndroidCodeQualityConfig

项目的build.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'
    }
}

quality.gradle:

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()
}

如果我 运行 a gradle 检查根项目它 运行 只在 :app 模块上,而不是整个项目。

我错过了什么?谢谢。

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

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'
}