I am trying to create a zip using gradle task but while running inside doLast{}
, it's throwing error saying : > Cannot call Task.dependsOn(Object...) on task ':app:testZip' after task has started execution.
MyCode :
doLast {
testDir.eachWithIndex { a, i ->
def dir = "${testDir[i]}"
def dirName = "${testDirName[i]}"
dependsOn tasks.create("testZip$c", Zip) {
from dir
baseName dirName
destinationDir(file("$dir"))
}
c++
} }
I don't find solution to this issue, please let me know, how can i run Zip task inside doLast{}
The error is being thrown because you are trying to create a new Task after the configuration phase has completed. Some possible solutions are to; remove the doLast() call, define a zip task outside of your doLast() or move zip logic into a method.