如何在 Android应用和 Java模块上运行gradlew lintDebug
?
以下是项目设置示例:
root-project
|- android-app
|- java-library
这是我到目前为止所做的:
gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.hasTask(":$project.name:lintDebug")) {
rootProject.subprojects.each { subprojects ->
// Do not add the same sources twice for this project
if (subprojects.name == project.name) {
return
}
// Append other modules source directories to this one
android.sourceSets.main.java.srcDirs += subprojects.files("./src/main/java")
}
}
}
将此代码段添加到android-app
模块允许您运行gradlew :android-app:lintDebug
以便在两个模块源文件上运行lint。
答案 0 :(得分:1)
为了在非基于android的模块上运行lint
,我不得不再次运行它:
lintDebug
在另一个任务名称
下再次运行lint gradlew lintDebug lintDebug2
// This is a work around to get our lint rules to run on our entire project
// When running lint, add other sources sets to android app source set to run on all modules
gradle.taskGraph.afterTask { task ->
if (task.name == "lintDebug") {
// Remove current source sets
android.sourceSets.main.java.srcDirs = []
// Append other modules source directories to this one
rootProject.subprojects.each { subprojects ->
android.sourceSets.main.java.srcDirs += subprojects.files("./src/main/java")
}
}
}
// Once we ran "lintDebug" on the current module, let's run it on all the others
// lintDebug -> afterTask -> add all source sets -> run again
task lintDebug2(dependsOn: "lintDebug")