What is the correct way to run 'clean' and 'build'...
# gradle
s
What is the correct way to run 'clean' and 'build' on all modules within a project? If I click 'clean' from the Gradle window on the root of the project, it will perform the task correctly, but if I put
dependsOn("clean")
in my script, it will only execute for one of the modules.
Some other semi-related questions because I can't find information about this anywhere: is it considered good practice to run things like 'build' and 'clean' on multiple modules from within a task? And one other question: what is the best method of running things one after another in a precompiled script? I just have a list of `dependsOn()`s right now and it's causing issues.
For reference, I am making a task that will clean my project, rebuild, locate the new artifacts, and then deploy them to our Sonatype repo. I have no idea if putting that all into a single task (using
dependsOn()
for cleaning and building, then manually locating the artifacts within their respective
lib
folders) is the proper way to do this.
t
If I click 'clean' from the Gradle window on the root of the project, it will perform the task correctly, but if I put
dependsOn("clean")
in my script, it will only execute for one of the modules.
Running
./gradlew clean
triggers all tasks with the same name in all modules - you can check it with
./gradlew -m clean
. Using
dependsOn("clean")
adds dependency only to one particular module
"clean"
task.
s
@tapchicoma I see. So the only way to clean multiple modules within a script is to run them all individually?
t
slightly different task goal, but will give you a direction:
Copy code
task cleanCache(type: Delete) {
    description "Clean all local build caches (Gradle and Android)"
    group "Build"
    dependsOn allprojects.collect { subproject ->
        subproject.tasks.matching {
            it.name == 'cleanBuildCache'
        }
    }
    delete gradle.ext.buildCacheDir
}
👍 1
s
that is very useful, thanks so much