简体   繁体   中英

How to run task after clean in Gradle

I'm Android Developer.

How to run a task(like methodA) after clean the project?

In other words,I want to execute a method after clean my Android project

Thanks!

In build.gradle:

def methodA() {
    print "Method A"
}

tasks['clean'] << {
    methodA()
}

The << operator is a shorthand to add a "do last" closure to a task. Alternatively:

tasks['clean'].doLast({
    methodA()
})
task removeSomeStuff(type: Delete) {
    //some stuff after  clean
    delete file('projectFilesBackup')
}

task clean(type: Delete) {
    delete rootProject.buildDir
    finalizedBy removeSomeStuff
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM