How to use Gradle
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:
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:
For more information about Groovy see the documentation.
Compiling Java files
There is a whole structure for Gradle to compile your projects with Gradle, the correct way is:
01. Create a new project and enter it:
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 (
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:
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/.