huaxiao
huaxiao

Reputation: 73

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!

Upvotes: 1

Views: 2653

Answers (2)

orium
orium

Reputation: 3813

task removeSomeStuff(type: Delete) {
    //some stuff after  clean
    delete file('projectFilesBackup')
}

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

Upvotes: 1

Barend
Barend

Reputation: 17444

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()
})

Upvotes: 2

Related Questions