First Gradle Project
This is just a super simple project to show some of the absolute basics of
gradle. This project was generated by running gradle init
followed by
selecting basic
, Groovy
, and the default project name.
The command gradle init
is used to initialize the folder I am currently in as
a gradle project. This command will prompt you for various options to describe
what kind of project you are working on. Based on what you answer determines
what gradle files and configs will be added to your current folder. Run tree
to see the directory structure after running gradle init
with the above
inputs:
tree .
Outputs:
. ├── build.gradle ├── gradle │ └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── README.org └── settings.gradle 2 directories, 7 files
One of the files worth noting is the gradlew
script. This is a script that is
generated by gradle init
to allow anyone to run our gradle tasks and build
instructions without even needing to have gradle installed. Lets look at the
build.gradle
file:
cat build.gradle
Outputs:
/* * This file was generated by the Gradle 'init' task. * * This is a general purpose Gradle build. * Learn more about Gradle by exploring our samples at https://docs.gradle.org/7.0.2/samples */ task firstTask { println 'Gradle Rocks!!' }
This task can be viewed by running: gradle tasks --all
and can be run with:
gradle firstTask
. One of the quirks about gradle that is important to note is
that the task can also be run with: gradle fT
. This is why it is the task name
is written with camel casing.