Gradle custom plugin

Where can I get tutorial on how to create gradle custom plugin, using zip in the task ?

Thanks In-advance.

Have you read the Gradle user guide yet?

Are you sure you don’t just need to create a custom task, as opposed to a plugin containing a task?

actually for other people. A tutorial on creating a custom plugin could be useful.

1 Like

Yes, I have read Gradle user guide.

I just can’t figure out how I can use gradle zip task inside my plugin.

for example :

I want to archive something like

task myZip(type: Zip){
      archiveName = "output.zip"
      destinationDir = "/dest"

      from "src"
}

where my plugin class is

class myPlugin  implements Plugin<Project> {
     // Create plugin extension, to
      input from other build scripts.
      project.task("myTask", type: Zip){
                archiveName = "output.zip"
                destinationDir = "/dest"

                 from "src"
         }
}

Thanks in-advance.

I just can’t figure out how I can use gradle zip task inside my plugin.

What exactly do you mean by that? Do you mean how to invoke the task? That would be the same as having it in your build script as ad hoc task: gradle myTask

The task will only be listed in your list of tasks (gradle tasks) if you actually apply the plugin. Do you apply the plugin in your build script?

apply plugin: myPlugin

BTW: Best practice in Java is that class names start with a capital letter.

We’re still trying to figure out exactly what you’re asking for. This statement seems to imply that you just need to create a zip file in some code in your plugin. If that’s the case, you don’t need to use the zip task, you just have to use the Java/Groovy APIs that create zip files. If that’s not what you need to do, then be specific about what you need to do. Try to state it in terms of what you actually need to happen, not how you assume you would use Gradle to do it.

This is not a plugin tutorial, but here are some good practices for creating a better DSL when writing a plugin - http://www.slideshare.net/ysb33r/idiomatic-gradle-plugin-writing