Does a custom plugin always need an associated task?

plugins

(Rohan Palkar) #1

I am still trying to understand the implementation of a custom plugin, and hence does a custom plugin always need an associated task (in the context that I am delegating the action) ?

Let me share my understanding/implementation that I am planning –
Please note : I have mapped the requirement into a general context due to organisational policies.

MyPlugin.groovy >>

class MyPlugin implements Plugin<Project> {
    void apply(Project target){
         def customExtension = target.extensions.create("customcars", Cars)
    }
}

Cars.groovy >>

class Cars {
    private final Size size = new Size()
    private final Capacity c = new Capacity()

     void carsize (Action<? super Size> action){
          action.execute(size)
     }

     void carcapacity (Action<? super Capacity> action){
          action.execute(c)
     }
}

Size.groovy (a groovy bean to have setters and getters) >>

class Size {
     def carType
     def carClass
}

Capacity.groovy (a groovy bean to have setters and getters) >>

class Capacity{
     def load
     def person
}

So in the build.gradle, I would like to provide the above details using my own DSL that I have tried to define above, inside of a task.

build.gradle >>

apply plugin : MyPlugin

task MyCustomTask {
     ... //does something
     customcars {
          carsize {
              carType = "sports" 
          }
          capacity {
               person = 2
          }
     }
}

I have also included customcars.properties under META-INF.

I could be completely off the track as I am still in the exploration phase of implementing this plugin - so please guide me on to a right one. :slight_smile:
Appreciate all responses and suggestions.

Thanks.

References -
Implementing Gradle plugins from Gradle guides.