Home Ask Login Register

Developers Planet

Your answer is one click away!

Woofbeans February 2016

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?

    println '********************* LAST ******************'


Nathan February 2016

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 ******************"


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.

Post Status

Asked in February 2016
Viewed 3,259 times
Voted 4
Answered 1 times


Leave an answer

Quote of the day: live life