Setting up your Gradle project
Open up a terminal and navigate to your home directory.
Create a directory for the project:
mkdir get-going-with-gradle
Navigate into the directory:
cd get-going-with-gradle
Create a Gradle project using the setup wizard:
gradle init
Select type of project to generate as basic:
1
Select build script DSL as Kotlin:
1
Choose the default project name:
<enter>
For Generate build using new APIs and behavior, choose the default no:
<enter>
Here’s how the console output looks when you follow the previous steps.
$ gradle init
Starting a Gradle Daemon (subsequent builds will be faster)
Select type of project to generate:
1: basic
2: application
3: library
4: Gradle plugin
Enter selection (default: basic) [1..4] 1
Select build script DSL:
1: Kotlin
2: Groovy
Enter selection (default: Kotlin) [1..2] 1
Project name (default: get-going-with-gradle):
Generate build using new APIs and behavior (some features may change in the next minor release)? (default: no) [yes, no]
> Task :init
To learn more about Gradle by exploring our Samples at https://docs.gradle.org/8.3/samples
BUILD SUCCESSFUL in 19s
2 actionable tasks: 2 executed
Interact with the new project
Try interacting with the project by running the help task:
./gradlew help
(Linux/Mac)
gradlew.bat help
(Windows)
$ ./gradlew help
> Task :help
Welcome to Gradle 8.3.
To run a build, run gradlew <task> ...
To see a list of available tasks, run gradlew tasks
To see more detail about a task, run gradlew help --task <task>
To see a list of command-line options, run gradlew --help
For more detail on using Gradle, see https://docs.gradle.org/8.3/userguide/command_line_interface.html
For troubleshooting, visit https://help.gradle.org
BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed
List all available tasks with the tasks task:
./gradlew tasks
(Linux/Mac)
gradlew.bat tasks
(Windows)
$ ./gradlew tasks
> Task :tasks
------------------------------------------------------------
Tasks runnable from root project 'get-going-with-gradle'
------------------------------------------------------------
Build Setup tasks
-----------------
init - Initializes a new Gradle build.
wrapper - Generates Gradle wrapper files.
Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root project 'get-going-with-gradle'.
dependencies - Displays all dependencies declared in root project 'get-going-with-gradle'.
dependencyInsight - Displays the insight into a specific dependency in root project 'get-going-with-gradle'.
help - Displays a help message.
javaToolchains - Displays the detected java toolchains.
kotlinDslAccessorsReport - Prints the Kotlin code for accessing the currently available project extensions and conventions.
outgoingVariants - Displays the outgoing variants of root project 'get-going-with-gradle'.
projects - Displays the sub-projects of root project 'get-going-with-gradle'.
properties - Displays the properties of root project 'get-going-with-gradle'.
resolvableConfigurations - Displays the configurations that can be resolved in root project 'get-going-with-gradle'.
tasks - Displays the tasks runnable from root project 'get-going-with-gradle'.
To see all tasks and more detail, run gradlew tasks --all
To see more detail about a task, run gradlew help --task <task>
BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed
Look at the different files in the project, excluding hidden files:
ls -l
(Linux/Mac)
dir
(Windows)
$ ls -l
total 18
-rw-r--r-- 1 Tom 197121 207 Sep 27 09:37 build.gradle.kts
drwxr-xr-x 1 Tom 197121 0 Sep 27 09:37 gradle
-rwxr-xr-x 1 Tom 197121 8639 Sep 27 09:37 gradlew
-rw-r--r-- 1 Tom 197121 2868 Sep 27 09:37 gradlew.bat
-rw-r--r-- 1 Tom 197121 377 Sep 27 09:37 settings.gradle.kts
Explore the project files
Look inside build.gradle.kts:
cat build.gradle.kts
(Linux/Mac)
type build.gradle.kts
(Windows)
$ cat build.gradle.kts
/*
* This file was generated by the Gradle 'init' task.
*
* This is a general purpose Gradle build.
* To learn more about Gradle by exploring our Samples at https://docs.gradle.org/8.3/samples
*/
Look inside settings.gradle.kts:
cat settings.gradle.kts
(Linux/Mac)
type settings.gradle.kts
(Windows)
$ cat settings.gradle.kts
/*
* This file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
* For more detailed information on multi-project builds, please refer to https://docs.gradle.org/8.3/userguide/building_swift_projects.html in the Gradle documentation.
*/
rootProject.name = "get-going-with-gradle"
Look at any hidden files or directories:
ls -la
(Linux/Mac)
dir/a
(Windows)
$ ls -la
total 124
drwxr-xr-x 1 Tom 197121 0 Sep 27 09:37 .
drwxr-xr-x 1 Tom 197121 0 Sep 27 09:35 ..
-rw-r--r-- 1 Tom 197121 223 Sep 27 09:37 .gitattributes
-rw-r--r-- 1 Tom 197121 108 Sep 27 09:37 .gitignore
drwxr-xr-x 1 Tom 197121 0 Sep 27 09:43 .gradle
-rw-r--r-- 1 Tom 197121 207 Sep 27 09:37 build.gradle.kts
drwxr-xr-x 1 Tom 197121 0 Sep 27 09:37 gradle
-rwxr-xr-x 1 Tom 197121 8639 Sep 27 09:37 gradlew
-rw-r--r-- 1 Tom 197121 2868 Sep 27 09:37 gradlew.bat
-rw-r--r-- 1 Tom 197121 377 Sep 27 09:37 settings.gradle.kts
Look inside the .gitignore file:
cat .gitignore
(Linux/Mac)
type .gitignore
(Windows)
$ cat .gitignore
# Ignore Gradle project-specific cache directory
.gradle
# Ignore Gradle build output directory
build
Commit the project into version control
Initialise this directory as a Git repository:
$ git init
Initialized empty Git repository in C:/workspace/get-going-with-gradle/.git/
Get all the files ready to be committed:
$ git add .
See what files are staged for commit:
$ git status
On branch main
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: .gitattributes
new file: .gitignore
new file: build.gradle.kts
new file: gradle/wrapper/gradle-wrapper.jar
new file: gradle/wrapper/gradle-wrapper.properties
new file: gradlew
new file: gradlew.bat
new file: settings.gradle.kts
Commit everything:
$ git commit -m "Initialise project"
[main (root-commit) ffee363] Initialise project
8 files changed, 376 insertions(+)
create mode 100644 .gitattributes
create mode 100644 .gitignore
create mode 100644 build.gradle.kts
create mode 100644 gradle/wrapper/gradle-wrapper.jar
create mode 100644 gradle/wrapper/gradle-wrapper.properties
create mode 100644 gradlew
create mode 100644 gradlew.bat
create mode 100644 settings.gradle.kts
Good work! You’ve just created your first Gradle project and committed it into version control.