Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle `it` property inside `build.gradle` closures

Tags:

gradle

groovy

Where does that property it stored in gradle?

subprojects {
    println it.class.name // DefaultProject_Decorated
    dependencies {
        println it.class.name // DefaultDependencyHandler_Decorated

Because it should not be the default it property of the closure. Or it should?

I think it something like def it = this or maybe I am wrong?

like image 906
lapots Avatar asked Dec 05 '25 13:12

lapots


1 Answers

In groovy closures, it is the default parameter passed to the Closure.

So:

def friendly = { "Hello $it" }

assert friendly('tim') == 'Hello tim'

So in the above cases, Gradle passes the object that the closure is helping to configure into the closure itself.

like image 141
tim_yates Avatar answered Dec 07 '25 15:12

tim_yates



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!