Execute Zip Task from Custom Plugin Task

How can I use Zip task in my custom plugin code?

I can create a task thus but then I don’t know how execute it. My goal is for my plugin to make a zip midway through its work and I want to do this without duplicating tools already available.

What’s the right approach?

def compress = project.task(type: Zip) { from rawInstaller.parentFile include rawInstaller.name archiveName "${rawInstaller.name}.zip" destinationDir rawInstaller.parentFile }

AntBuild’s task is probably the right approach

project.ant.zip(destfile: destZip, basedir: rawInstaller.parentFile.absolutePath, includes: rawInstaller.name)

The universal rule is that you don’t ever write code that directly executes tasks. You write code that sets up task dependencies, so that when a task executes that needs to have another task executed previously, you can guarantee that. This is done with the “task.dependsOn()” method.

If you’re writing procedural code that has to compress a file and do something with that result, you won’t be able to use conventional Gradle tasks to do that. However, as the other responder indicated, you can reuse the provided Ant task to do this in a procedural fashion.

Ok. That makes sense. I’m in the midst of a process and used ant task. It worked well.