Hey I am trying to define single task that can run...
# gradle
i
Hey I am trying to define single task that can run all static checks (ktlint, android lint, detekt) and tests - single taks that could verify project correctness. As far as I know only way to do it in gradle is to define task that depends on other tasks so they will run before:
Copy code
task("prCheck") {
    afterEvaluate {
        // Non-android modules do not have lint task
        val lintDependencies = subprojects.mapNotNull { "${it.name}:lint" }

        val taskDependencies = mutableListOf<String>("ktlintCheck", "detekt", "testDebugUnitTest")
        taskDependencies.addAll(lintDependencies)
        dependsOn(taskDependencies)
    }
}
Above task works well for android lint, detekt, ktlint, however it fails to resolve
testDebugUnitTest
task 🤔
Copy code
FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':prCheck'.
> Task with path 'testDebugUnitTest' not found in root project 'android'.
g
Where do you create this task? It will work only in module with this task
Also, it may be somehow related to task creation
i
I am defining
prCheck
task in project root level
build.gradle.kts
, so and I am able to run it in project root like this
./gradlew prCheck
- the only problem is
testDebugUnitTest
task that comes from Android FYI I can run
./gradlew testDebugUnitTest
without any problems - the problem starts when I want to use it as dependency
g
No, it will not work like that, you cannot just define task and depend on task in another module
Dependencies by default only resolve tasks in the same module
Instead, apply this task in app your modules
You can run it like ./gradlew testDebugUnitTest only because Gradle resolve tasks from all modules and run all of them (with the same name), but this doesn't work in task dependencies, so to implement such check task: 1. Apply it to every module, so it will resolve dependencies and Gradle will.run check task on every module where this task exists 2. You probably can get task from submodule directly, like
submodules["myModule"].tasks["testDebugUnitTest]
and set dependency on it, but didn't try this approach, and all default Gradle task work like 1, not like 2