Skip to main content

Build File Basics

A build script details build configuration, tasks, and plugins. Every Gradle build comprises at least one build script. In the build file, two types of dependencies can be added:

  1. The libraries and/or plugins on which Gradle and the build script depend.
  2. The libraries on which the project sources depend.

Build script

The build script is either a build.gradle file written in Groovy or a build.gradle.kts file in Kotlin. Example of the build script:

settings.gradle.kts
plugins {
id("application") (1)
}

application {
mainClass = "com.example.Main" (2)
}

(1) Add plugins.
(2) Use convention properties.

1. Add plugins

Plugins extend Gradle's functionality and can add more tasks to a project. Adding a plugin to a build is called applying a plugin:

plugins {
id("application")
}

The application plugin facilitates creating an executable JVM application. Applying the Application plugin also implicitly applies the Java plugin. The java plugin adds Java compilation along with testing and bundling capabilities to a project.

2. Use convention properties

A plugin adds tasks to a project. It also adds properties and methods to a project. The application plugin defines tasks that package and distribute an application, such as the run task. The Application plugin provides a way to declare the main class of a Java application, which is required to execute the code.

application {
mainClass = "com.example.Main"
}