# How Gradle Works Part 3 - Build Script

DevFeed: [How Gradle Works Part 3 - Build Script](<https://devfeed.tech/articles/how-gradle-works-part-3-build-script-24644.md>)

Original publisher: [Read original article](<https://blog.gradle.org/how-gradle-works-3>)

Author: Bo Zhang

Published: 2023-03-10T02:00:00Z

Content type: article

Language: en

Sources: [The Gradle Blog](<https://devfeed.tech/sources/the-gradle-blog.md>)

Topics: [Gradle](<https://devfeed.tech/topics/gradle.md>), [Groovy](<https://devfeed.tech/topics/groovy.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Programming language](<https://devfeed.tech/topics/programming-language.md>)

Tags: [build](<https://devfeed.tech/tags/build.md>), [domain-specific-language](<https://devfeed.tech/tags/domain-specific-language.md>), [gradle](<https://devfeed.tech/tags/gradle.md>), [groovy](<https://devfeed.tech/tags/groovy.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [script](<https://devfeed.tech/tags/script.md>)

## AI overview

The third article in the How Gradle Works series explains what happens during Gradle build script execution. It describes the Kotlin and Groovy DSLs, including lambda and closure syntax, omitted parentheses, trailing function arguments, chained method invocation, and receiver or delegate objects mapped to Gradle API methods.

## Source excerpt

Previously on How Gradle Works: How Gradle Part 1 - Startup How Gradle Part 2 - Inside The Daemon This is the third blog of the series How Gradle Works. In this blog we'll explain what happens during build script execution. Kotlin & Groovy DSL If you are a Java developer, when you open any Gradle build script (for example build.gradle.kts or build.gradle), the first thing that might confuse you is the special syntax of curly braces: // Kotlin DSL: plugins { id("some.plugin") version "0.0.1" } // or Groovy DSL: plugins { id "some.plugin" version "0.0.1" } What's this? What happens when Gradle executes these kinds of scripts? The short answer is: they are DSLs (Domain Specific Language) on top of the Kotlin programming language for .gradle.kts files, or on top of the Groovy programming language for .gradle files. These DSLs have some implicit rules, making them appear very confusing. Implicit Rule 1: Lambda/Closure First of all, { ... } is a special object in both Groovy and Kotlin. This object is called a lambda in Kotlin, or a closure in Groovy. They're similar to function objects in other programming language, like Java's lambda, or JavaScript's function object. You can think of plugins { ... } as a method invocation in which a Kotlin lambda object or Groovy closure object is passed as the argument, because both Groovy and Kotlin allow you to omit parentheses: plugins(function() { ... }) Also, there is one noteworthy DSL: in Kotlin/Groovy, if the last parameter of a function is a lambda/closure, it's allowed to be put outside of parentheses. For example, the following code snippet: tasks.register("myTask") { ... doLast { ... } } is equivalent to: tasks.register("myTask", function() { ... doLast(function() { ... }) }) The code inside the function may be executed immediately or later, depending on the implementation of the specific method. Implicit Rule 2: Chained Method Invocation In the plugins { } example above, the Kotlin version: id("some.plugin") version "0.0.1