Reputation: 55527
How can I run gradlew lintDebug
on both the Android app and the Java module?
Here is an example project setup:
root-project
|- android-app
|- java-library
Here is what I have done so far:
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")
}
}
}
Adding this code snippet into the android-app
module allows you to run gradlew :android-app:lintDebug
in order to run lint on both modules source files.
Upvotes: 4
Views: 1140
Reputation: 55527
In order to run lint
on non-android based modules, I had to run it a second time:
lintDebug
Run lint again under another task name
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")
Upvotes: 1