title: Confusing Property Delegation in Gradle's Kotlin DSL
body: <p>Below is the code snippet that I came across in gradle's documentation
  <strong><a href="https://docs.gradle.org/current/userguide/tutorial_using_tasks.html" rel="nofollow noreferrer">https://docs.gradle.org/current/userguide/tutorial_using_tasks.html</a></strong></p>
  
  <pre><code>val hello by tasks.registering {
      doLast {
          println("Hello Earth")
      }
  }
  hello {
      doFirst {
          println("Hello Venus")
      }
  }
  </code></pre>
  
  <p>In the above, <em>hello</em> is a TaskProvider type which provides task definition/action. The second call to hello is to extend the behavior of the task. </p>
  
  <p>This <em>delegate</em> use looks slightly confusing to me. Following are the questions which are bugging me:</p>
  
  <p>1) On inspecting the decompiled byte-code, I see <em>tasks.registering</em> returns <strong>RegisteringDomainObjectDelegateProviderWithAction</strong> object which should be used as the delegate and hence should provide getValue() and setValue() methods for <em>delegate</em> to work but as I saw, methods are not provided. Instead the class <strong>RegisteringDomainObjectDelegateProviderWithAction</strong> has a <strong>delegateProvider</strong> property of type <em>tasks</em> which is supposed to provide the <em>delegate</em>. Can any one help me understand, how delegation works here?</p>
  
  <p>2) The second call is supposed to add behavior to the <em>hello</em> task. Since <em>hello</em> is a property, how are we able to pass a lambda/behavior to it? What am I missing?</p>
  
  <p>I have already seen kotlin documentation which provides good explanation of delegates but doesn't aid in understanding the above case <em><a href="https://kotlinlang.org/docs/reference/delegated-properties.html" rel="nofollow noreferrer">https://kotlinlang.org/docs/reference/delegated-properties.html</a></em></p>
  
  <p>I would appreciate a detailed explanation as I am new to Kotlin.</p>