The build script is where every configuration change happens; you need to read it fluently.
A Gradle build has two script files at its root:
settings.gradle.ktsnames the build (rootProject.name) and lists subprojects withinclude("app", "lib"). It also configures where plugins come from (pluginManagement) and, in modern builds, where dependencies come from (dependencyResolutionManagement).build.gradle.ktsconfigures a project: which plugins to apply, which repositories to search, and which dependencies the code needs.
Scripts use the Kotlin DSL (.kts, the default since Gradle 8) or the older Groovy DSL (build.gradle). The Kotlin DSL is type-safe with IDE completion; the concepts are identical.
A minimal JVM app:
plugins { id("java"); id("application") }
repositories { mavenCentral() }
dependencies { implementation("com.google.guava:guava:33.4.0-jre") }
application { mainClass = "com.acme.App" }Plugins add tasks and conventions. The java plugin expects sources in src/main/java, tests in src/test/java and resources in src/main/resources, and defines compileJava, test, jar and build. Outputs go to build/.
group and version identify your artifacts. The java { toolchain { languageVersion = JavaLanguageVersion.of(21) } } block makes Gradle compile with a specific JDK regardless of which one runs Gradle, which keeps builds reproducible across machines.
Example
// settings.gradle.kts
rootProject.name = "demo"
// build.gradle.kts
plugins {
java // or id("java")
application
}
group = "com.acme"
version = "1.0.0"
repositories { mavenCentral() }
dependencies {
implementation("com.google.guava:guava:33.4.0-jre")
testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
java { toolchain { languageVersion = JavaLanguageVersion.of(21) } }
application { mainClass = "com.acme.App" }
tasks.test { useJUnitPlatform() }
// Layout: src/main/java, src/main/resources, src/test/java; outputs in build/Remember
- settings.gradle.kts names the build and lists subprojects
- build.gradle.kts applies plugins, repositories and dependencies
- The java plugin defines the src/main and src/test layout and the build tasks
- Toolchains pin the JDK used to compile