Skip to content
AgileLogics
6 min read

Gradle Basics

Prerequisites: Classes and objects

Real Kotlin projects are built with Gradle — a build tool that compiles your code, downloads libraries (dependencies), runs tests, and packages the result. Android projects always use Gradle, and so do most server and library projects. (Maven is the main alternative.)

Creating a project

IntelliJ IDEA creates Gradle projects for you, or from a terminal with Gradle installed:

gradle init --type kotlin-application --dsl kotlin
my-app/
├── settings.gradle.kts        # project name, list of modules
├── gradlew / gradlew.bat      # the Gradle wrapper scripts
├── gradle/libs.versions.toml  # dependency versions (version catalog)
└── app/
    ├── build.gradle.kts       # this module's build script
    └── src/
        ├── main/kotlin/       # your code
        └── test/kotlin/       # your tests

Always run Gradle through the wrapper — ./gradlew (or gradlew.bat on Windows). It downloads the exact Gradle version the project expects, so every developer and CI server builds the same way.

The build script

Build scripts are themselves written in Kotlin (.gradle.kts):

plugins {
    kotlin("jvm") version "2.2.0"
    application
}

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2")
    testImplementation(kotlin("test"))
}

kotlin {
    jvmToolchain(21)
}

application {
    mainClass = "com.example.AppKt"
}
  • plugins add capabilities: compiling Kotlin, building a runnable application.
  • repositories say where to download libraries — Maven Central is the main public repository.
  • dependencies list libraries as "group:name:version". implementation is needed to build and run; testImplementation only for tests.
  • jvmToolchain(21) compiles for Java 21, downloading it if needed.

Everyday commands

./gradlew build        # compile, run tests, package
./gradlew run          # run the application
./gradlew test         # run tests only
./gradlew dependencies # show the full dependency tree

In IntelliJ, the Gradle tool window lists these tasks; after editing a build script, click the Sync icon to reload it.

Common mistakes

  • Running a globally installed gradle instead of ./gradlew, and getting a different Gradle version.
  • Adding dependencies without checking them. Every library is code that runs with your app's permissions — prefer well-maintained ones.