Gradle is a build automation tool based on Groovy. It supports several programming languages: C++, Kotlin, JavaScript, Scala, Swift and Groovy.
You can use your operating system’s package manager to search and install, examples: Windows(winget
, choco
, …), macOS, GNU/Linux(apt
, pacman
, …).
However, if you want to install binaries directly, just download the latest version directly from the releases page, unzip, install, like this:
Taking as an example the most current version according to the publication date of this article:
8.1.1
.
Once installed, check if everything is right by running the command plus the argument to get the version:
For Windows users unzip and move to C:/
drive and copy folder path C:\gradle-8.1.1\bin
and add to System Environment Variables, then open Powershell or Windows Terminal even CMD
and run the same command to see the version.
Gradle is written in Groovy and to run a basic Hello, World!, just create a file named build.gradle
and insert the content below:
Now inside the same directory that build.gradle
is in terminal run the command:
It will load the process and then display the message:
Hello, Gradle!
.
For more information about Groovy see the documentation.
There is a whole structure for Gradle to compile your projects with Gradle, the correct way is:
Inside your project, run the command:
The Wizard will start with several questions, see the output below for the answers I passed:
Remembering that some I left blank, so it was answered as the default answer (
default
)
After that several files and folders were created including ./gradlew
(A shell script) and ./gradlew.bat
(A batch script). And it is with them (gradlew
for Linux and macOS; and gradlew.bat
for Windows) that we will run our example.
But first of all let’s edit the file inside our project in the path:
vim app/src/main/java/hello/App.java
And change it however you want, example:
Now you can build using ./gradlew build
or ./gradlew.bat build
, but if you want to build and run automatically run the command:
The output will be similar will be:
For more information use gradle --help
and go to: https://gradle.org/.
java cpp kotlin javascript groovy swift scala