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.
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'
}
Links
Software
- Gradle (Windows, macOS, Linux)
- Android Studio (Windows, macOS, Linux)
- IntelliJ IDEA (Windows, macOS, Linux)
- Eclipse, with the Buildship plugin (Windows, macOS, Linux)