我有一个带有多个库的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'
}
}
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()
}
如果我在根项目上运行gradle检查,它将仅在:app modul上运行,而不是整个项目。
我想念什么?谢谢。
答案 0 :(得分:0)
这可能并非您要找的答案,但是我的解决方案是添加
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'
}