How to Zip a directory in custom Task class in Kotlin

I would need some help on using the built-in zipping feature.
I have a custom plugin and a task in my kotlin class.
I would like to make use of the Gradle’s zipping feature instead of using 3rd party dependencies.

All the examples I see on the internet explain on how to do it in the build script.
But I would like to perform the zipping from my kotlin task class inside the @TaskAction/execute().

Could you please give an example using the ZipAction or ZipCopyAction.

1 Like

Afair there is no built-in supported way to create a zip archive besides using a task of type Zip.

So in that case I will have to register a task of type Zip in my build script with inputs like

  1. directory to zip
  2. zip name, etc.,

I would like to perform certain things in my custom task and then zip a directory.
Could you please tell me how do I invoke that zip task from my custom task in kotlin class?

You cannot invoke a task

Make your custom task prepare the files to zip in a directory, then make a zip task that zips that directory.

Thanks for your answer!

1 Like