gpt4 book ai didi

android - 在所有模块上运行 android checkstyle

转载 作者:行者123 更新时间:2023-12-05 00:00:07 25 4
gpt4 key购买 nike

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

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

质量.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()
}

如果我对根项目运行 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'
}

关于android - 在所有模块上运行 android checkstyle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51840917/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com