Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing the configure closure from a gradle extension

Tags:

plugins

gradle

I'm writing a plugin in which do something like the following:

project.extensions.create('myExtension', new MyExtension(project))

where MyExtension is the class that defines my new functionality.

Now, in gradle.build I can do this:

myExtension {
    // configure cool stuff
}

What I would like to do now, is to "consume" a couple of the things in this configure closure, and pass the rest of the closure as-is to a task I defined, using project.configure(myTask, closure). However, I have no idea how to

  1. Access the configure closure from the MyExtension class.

  2. "Consume" some of the closure, i.e. access some of the properties on the closure and then strip them, leaving another closure which has all the untouched things but nothing else

Any pointers would be greatly appreciated =)

like image 440
Tomas Aschan Avatar asked Dec 07 '25 06:12

Tomas Aschan


1 Answers

It's not how extensions work. The closure gets evaluated immediately in order to configure the extension object. After that, the closure is gone. Typically, a plugin will use the (information contained in the) extension object to further configure tasks.

PS: It's extensions.create('myExtension', MyExtension, project), not project.extensions.create('myExtension', new MyExtension(project)).

like image 129
Peter Niederwieser Avatar answered Dec 09 '25 19:12

Peter Niederwieser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!