/commands/kotlin/gradle-init-kotlin-application
gradle init --type kotlin-application: create a new Kotlin project
- tool
- Kotlin
- versions
- Gradle 8.x – 9.x, Kotlin 2.x
- os
- linux, macos, windows
gradle init --type kotlin-application --dsl kotlin creates a new Kotlin/JVM command-line project in the current directory: a settings.gradle.kts, an app subproject with the org.jetbrains.kotlin.jvm and application plugins, a sample class, a test using the Kotlin test library, and the Gradle Wrapper. Run it with ./gradlew run. Missing options are asked interactively; add --use-defaults to accept the defaults without prompts.
Create and run the project
mkdir hello-kotlin && cd hello-kotlin
gradle init --type kotlin-application --dsl kotlin \
--project-name hello-kotlin --package com.example --java-version 21 --use-defaults
./gradlew run
./gradlew testOn Windows cmd.exe and PowerShell, use gradlew.bat run (or .\gradlew run). The first run downloads Gradle, the Kotlin Gradle plugin and the dependencies, so it needs network access and takes a while.
Options
| Option | Effect |
|---|---|
| --type kotlin-application | Command-line application in Kotlin/JVM (kotlin-library and kotlin-gradle-plugin also exist) |
| --dsl kotlin | groovy | Build script language; Kotlin DSL is the default for most build types |
| --project-name NAME | Project name; defaults to the directory name |
| --package com.example | Package of the generated sources; defaults to the project name |
| --java-version 21 | Java version used by the project (toolchain) |
| --into DIR | Generate the project in another directory |
| --split-project / --no-split-project | Split functionality across several subprojects or keep one app subproject |
| --use-defaults | Do not prompt for options that were not given |
| --overwrite | Allow existing files in the directory to be overwritten |
What gets generated
settings.gradle.kts: the root project name and the includedappsubproject.app/build.gradle.kts: the Kotlin JVM andapplicationplugins,mavenCentral()as repository, test dependencies, andapplication { mainClass = ... }pointing at the generated main class.app/src/main/kotlin/...andapp/src/test/kotlin/...: a sample class and its test, in the package you chose.gradlew,gradlew.bat,gradle/wrapper/: the Gradle Wrapper, to commit with the project.gradle/libs.versions.toml: a version catalog for dependency versions (recent Gradle versions).
Pitfalls
- Files already present. If the directory is not empty,
gradle initasks before continuing;--overwriteskips the question and replaces files. Run it in a new folder. - Interactive prompts in CI. Without
--use-defaults(or all options given), the task waits for input. Pass every option in scripts. - JDK not found. The generated build uses a Java toolchain; if no matching JDK is installed, Gradle reports that it cannot find one. Install that version or change
--java-version. - Adding dependencies. Put them in
app/build.gradle.ktsunderdependencies { implementation(...) };./gradlew dependenciesshows the resolved tree (see gradle dependencies).
Confirm it worked
./gradlew run prints the sample greeting and ./gradlew test ends with BUILD SUCCESSFUL. Open the folder in IntelliJ IDEA and it is recognised as a Gradle project.
FAQ
Do I need Gradle installed to use the generated project?
Only to run gradle init once. The generated project contains the Gradle Wrapper (gradlew and gradlew.bat), which downloads the right Gradle version for everyone who builds it afterwards.
Kotlin DSL or Groovy DSL?
The Kotlin DSL (build.gradle.kts) is the default for most build types and gives code completion and type checking in IntelliJ IDEA. Choose --dsl groovy only to match existing Groovy builds.
Can I use IntelliJ IDEA's New Project wizard instead?
Yes. It creates a similar Gradle project with the Kotlin JVM plugin. gradle init is the editor-independent way, and handy in scripts and CI.