Scrungepipes
Scrungepipes

Reputation: 37581

Gradle tasks.build.doLast() not being invoked

I want to perform some file copying after a build has been performed and found some answers saying tasks.build.doLast() can be used. However if I add this to my (or to any gradle) script, then its not being invoked.

Does it have to be invoked explicity, if so how?

tasks.build.doLast(){
    println '********************* LAST ******************'
}

Upvotes: 2

Views: 5101

Answers (1)

Nathan
Nathan

Reputation: 3190

In the absence of Gradle version information I will assume you are using the latest and pull from the current documentation. Your current code looks a little off with the doLast() dot notation.

If you were writing a task to print a line, the code below will work:

task1 {

    //Task configuration goes here.

    doLast {
        println "********************* LAST ******************"
    }
}

If you are using doLast to finalize another task Gradle has a method for doing that. You can use finalizedBy. Below is an example:

task1 {
        println "Task 1 successful"
}

task2 {

        println "********************* LAST ******************"
}    

task1.finalizedBy task2

For more information on Gradle Tasks you should check out Chapter 14 and Chapter 17 of the Gradle documentation. There are examples of the different ways to define classes included in those short chapters.

Upvotes: 5

Related Questions