How to configure and run a zip task, at runtime

Hi all,

I need to write a gradle build file which, amongst other things, grabs certain build artifacts, and generates a zip file containing these.

The artifacts are not available at configuration time, so I am unable to configure my zip task at configuration time.

In earlier versions of gradle, I was able to explicitly invoke the task, using something like :

Zip distCopy = task("distCopy"+recipient.@name.text(), type: Zip)

However, this is not available in more recent versions of gradle.

So, at the moment, I am configuring my zip task at runtime, in a ‘doLast’ block.

How do I convince it to actually execute?



At first glance, I’d recommend looking at the “Distribution Plugin” ( to help you with a zip task in general instead of writing your own.

However, if that doesn’t suit you, I’d go through Ch 6 of the user guide again, specifically focusing on 6.7 for tying your task into the main build pipeline. (

Thanks, topher

It’s not recommended to explicitly call the ‘execute’ method of a task. This is done by Gradle internally. If you want a task to be executed as part of your task execution graph, you will need to make a task dependency of another task or directed request its execution from the command line.

I’d need to have more information to determine what can be configured during configuration or execution time. Please provide more information on your use case.