https://kotlinlang.org logo
#android
Title
# android
v

Vincent Williams

07/29/2020, 8:06 PM
Copy code
tasks.register("clean", Delete::class) {
    delete(rootProject.buildDir)
}
this is the default clean task. Does this need to look different for multi-module projects or will this work just fine? maybe
delete(rootProject.buildDir)
needs to be run on each buildDir? im not sure though
g

gildor

07/30/2020, 3:32 AM
In multi module project every module should have own clean task
v

Vincent Williams

07/30/2020, 3:32 AM
How would I run all those tasks simultaneously
g

gildor

07/30/2020, 3:32 AM
and this task implementation doesn’t look right, every module has build dir, not only rootProject
why do you need custom clean task at all?
v

Vincent Williams

07/30/2020, 3:34 AM
for the same reason you would need any clean task. I want to clear out any generated code
g

gildor

07/30/2020, 3:34 AM
but default clean task already doing this
v

Vincent Williams

07/30/2020, 3:35 AM
the code I posted is the default...
g

gildor

07/30/2020, 3:35 AM
if you need something custom (to delete some dir outside of
build
dirrectory, you just add your custom task as dependency to default
clean
task
It is not
v

Vincent Williams

07/30/2020, 3:35 AM
at least it was in the project build file when the project was created
g

gildor

07/30/2020, 3:35 AM
It’s not “default” it’s just generated by some project generator
there is default clean task
v

Vincent Williams

07/30/2020, 3:36 AM
thats what is run by clicking "clean"?
g

gildor

07/30/2020, 3:39 AM
“clicking”?
see, every module with base plugin has clean task: https://docs.gradle.org/current/userguide/base_plugin.html
except root module, which doesn’t apply any plugins (at least in default android project), so this task is just delete root build dir, but it really not important, you just can delete it
all modules where you really need clean, already have clean task
this custom task just deletes root build dir
v

Vincent Williams

07/30/2020, 3:43 AM
ohh ok that makes sense. I didnt know that there was a default clean task already
g

gildor

07/30/2020, 3:51 AM
Yes, and returning to your question
How would I run all those tasks simultaneously
This how Gradle works by default with all the tasks, if you do this:
./gradlew clean
. Gradle will check every module, if it has task clean and run it, if it doesn’t, nothing happen If you do this:
./gradlew :some-module:clean
it will run clean task only on some-module, or
./gradlew :clean
it will run clean task only on root module
v

Vincent Williams

07/30/2020, 3:53 AM
ah ok. I think I need to learn more about gradle...
15 Views