Introduction
A .gradle file is a build script for Gradle,
the build tool most used for Java, Kotlin and Android projects. The build script,
build.gradle, says which plugins the project uses, where to download
libraries from and which libraries it needs; settings.gradle names the
project and the subprojects it is made of.
Scripts are written in Groovy, or in Kotlin when named build.gradle.kts
and settings.gradle.kts. Projects usually include the Gradle wrapper,
gradlew, a small script that downloads and runs the right Gradle
version.
Structure
A build script is a program in Groovy or Kotlin that configures the build through
blocks. plugins applies plugins, such as java or the Android
application plugin, which add tasks like build and test.
repositories lists where libraries come from, such as Maven Central, and
dependencies lists them by group, name and version, each in a
configuration such as implementation or
testImplementation. The script kinds, blocks, configurations and
repositories are listed on the scripts and
blocks page, and gradle.properties, the version catalog and the
wrapper on the properties, catalog and
wrapper page.
plugins {
id 'application'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'com.google.guava:guava:33.0.0-jre'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
}
application {
mainClass = 'com.example.App'
}
Not described
Known, not yet covered
- Reference: map notation for dependencies,
platform(), the classifier and@extforms, and thepluginManagementdetails, all in the Gradle manual; they belong on the scripts page. - Viewer: there is no viewer for Gradle files yet, so build scripts are not opened or shown.
Links
Software
- Gradle – the build tool that runs the scripts (Windows, macOS, Linux)
- Android Studio – Google’s Android IDE, which builds every project with Gradle (Windows, macOS, Linux)
- IntelliJ IDEA – JetBrains’ Java and Kotlin IDE, which imports Gradle builds (Windows, macOS, Linux)
- Eclipse – Java IDE that imports Gradle builds with the Buildship plugin (Windows, macOS, Linux)
Reference
- Gradle User Manual – the official documentation