Build Scripts and DSL
The scripting layer: Groovy versus Kotlin DSL, what belongs in a settings script versus a build script, and building blocks like buildscript and extra properties. Interviewers start here to see whether you read build scripts as code or as inert configuration.
on this pageshowhide
explore
- DSL Languages30 questions
- Kotlin DSL Fundamentals5 questions
- Kotlin Type-Safe Model Accessors5 questions
- Kotlin Task Configuration API5 questions
- Groovy DSL Fundamentals5 questions
- Groovy Dynamic Properties & Delegation5 questions
- Groovy to Kotlin DSL Migration5 questions
- Script File Types30 questions
- Settings Script5 questions
- pluginManagement Block5 questions
- dependencyResolutionManagement Block5 questions
- Build Script Structure & Evaluation5 questions
- Init Scripts5 questions
- Script Plugins (apply from)5 questions
- Script Building Blocks25 questions
- buildscript {} Classpath5 questions
- Extra (ext) Properties & Scoping5 questions
- gradle.properties & Project Properties5 questions
- DSL Extensions & Conventions5 questions
- Injected Services and serviceOf5 questions
questions
85 · 3 sectionsIn a build.gradle Groovy script, what is a block like dependencies { ... } actually, and how does Gradle execute it?
basics
~10 sIt's a Groovy closure passed to a method named dependencies. Gradle calls that method, runs the closure, and the closure's calls configure the dependencies object.
What is the `ext` namespace in a Groovy build script, and why do you need it to define your own custom project properties?
basics
~20 sext is Gradle's extra-properties container. You write ext.myVersion = '1.0' to add a custom property, then read it as myVersion anywhere in the project. It exists because Project only stores arbitrary user properties through this namespace.
You're starting to migrate a build.gradle to build.gradle.kts. What are the first mechanical changes you make to the file — the filename and the most common syntax fixes?
basics
~10 sRename build.gradle to build.gradle.kts. Then wrap all strings in double quotes (Kotlin has no single-quote strings), and replace each '=' or Groovy assignment so it follows Kotlin syntax.
How do you apply plugins in build.gradle.kts using the plugins {} block, and what makes that block special?
basics
~10 sUse the plugins {} block: list plugins by id and version, e.g. id("org.springframework.boot") version "3.x", or use built-in accessors like kotlin("jvm") or java. It applies plugins declaratively at the top of the script.
What is build.gradle.kts, and how does it differ from build.gradle when describing a Gradle project?
basics
~20 sbuild.gradle.kts is a Gradle build script written in Kotlin (the Kotlin DSL), instead of build.gradle which uses the Groovy DSL. Both configure the same project; the .kts file is Kotlin source compiled before the build runs.
Why must the plugins {} block appear first in a build.gradle(.kts) file, and what happens if you put code before it?
basics
~10 sThe plugins {} block must be the first statement (after any buildscript/pluginManagement). Gradle parses it specially and early to resolve plugins. Putting other code before it causes a build failure.
What is the dependencyResolutionManagement {} block, and which Gradle build file does it belong in?
basics
~10 sIt is a block in settings.gradle(.kts) — not build.gradle — where you centrally declare repositories and version catalogs for the whole build instead of repeating them in each module.
What is a Gradle init script, and what are the different ways Gradle discovers and applies one?
basics
~10 sAn init script runs before the build itself, letting you configure Gradle globally. Gradle applies it from ~/.gradle/init.gradle(.kts), any file in ~/.gradle/init.d/, or via the --init-script command-line flag.
What is the pluginManagement {} block and where must it appear in a Gradle build?
basics
~10 sIt is a block in settings.gradle(.kts) that configures how plugins are resolved. It must be the first block in the settings file, before anything else.
What is a script plugin in Gradle, and how do you apply one?
basics
~10 sA script plugin is a plain Gradle script (e.g. other.gradle.kts) holding shared build logic. You apply it with apply(from = "other.gradle.kts") in Kotlin DSL or apply from: 'other.gradle' in Groovy.
What is the buildscript {} block in a Gradle build script, and what goes inside it?
basics
~10 sbuildscript {} configures the build script itself: it declares repositories {} and dependencies { classpath(...) } that put plugin and helper jars on the classpath the script needs to compile and run.
What is a Gradle extension, and how does adding one give a plugin its own configuration block in the build script?
basics
~10 sAn extension is an object a plugin registers via project.extensions.create("name", Type::class.java). Gradle then exposes a build-script block named after it (e.g. name { ... }) that configures that object.
What are Gradle's extra (ext) properties, and how do you declare and read them in a build script?
basics
~20 sExtra properties are arbitrary user-defined key/value pairs attached to a Gradle object. You set them with ext { key = value } (Groovy) or by extra (Kotlin) and read them back by name later in the script.
What is the gradle.properties file used for, and how does it differ from passing -P on the command line?
basics
~20 sgradle.properties stores key=value project properties persisted in the repo (or ~/.gradle for the machine). -P sets the same kind of project property ad-hoc on one command line. Both surface as project properties; -P overrides the file.
Under the configuration cache, how do you replace project.exec, project.javaexec, and project.copy inside a task action?
basics
~10 sInject ExecOperations and call execOps.exec/javaexec for processes, and inject FileSystemOperations and call fsOps.copy/sync/delete for files. These replace the project.* calls that aren't allowed at execution time with the configuration cache on.