How to configure and run a zip task, at runtime


(Sean Van Buggenum) #1

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)
..
..
distCopy.execute()

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?

thanks!

sean


(Chris Marks) #2

At first glance, I’d recommend looking at the “Distribution Plugin” (http://www.gradle.org/docs/current/userguide/distribution_plugin.html) 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. (http://www.gradle.org/docs/current/userguide/tutorial_using_tasks.html#N102B0)

Thanks, topher


(Benjamin Muschko) #3

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.