Gradle is a general build tool that supports various languages, such as java, groovy, kotlin, scala, c++, etc.
You can easily manage your project dependencies through the ‘build.gradle’ file. Groovy will automatically download the necessary components specified in the script. The script can be written in Groovy or Kotlin.
There are different ways to initialize your project with gradle. One is through the cli command gradle init
. If you’re using IntelliJ, you can simply create a new project using gradle. If you’re using spring, you can also download the starter project file through spring initializr.
Here are the basic components of the ‘build.grade’ file.
plugins {
id 'java'
id 'org.springframework.boot' version '2.6.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'junit:junit:4.13.1'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
Plugins add extra functionalities to your gradle build. For instance, adding the java plugin will add gradle tasks that will help you with your java development, such as compiling, testing, or generating java docs. You can check out more info here
You can either use core plugins or other free Gradle plugins.
repositories
is where you tell Gradle to download it from.
dependencies
is where you decide which dependencies and versions your project will need. There are different configurations you can use for this.
Tasks can also be defined in the file, which will execute during the build. They can be explicitly defined in the script, or they can automatically be added through the plugins.
If you want to get more detailed error messages, create a new file named ‘gradle.properties’ in the same directory as ‘build.gradle’ and add the following line:
org.gradle.warning.mode=all