Skip to content

/commands/kotlin/gradle-init-kotlin-application

gradle init --type kotlin-application: create a new Kotlin project

The commands on this page have not been executed by our verification runner yet.updated
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

bash
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 test

On 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

OptionEffect
--type kotlin-applicationCommand-line application in Kotlin/JVM (kotlin-library and kotlin-gradle-plugin also exist)
--dsl kotlin | groovyBuild script language; Kotlin DSL is the default for most build types
--project-name NAMEProject name; defaults to the directory name
--package com.examplePackage of the generated sources; defaults to the project name
--java-version 21Java version used by the project (toolchain)
--into DIRGenerate the project in another directory
--split-project / --no-split-projectSplit functionality across several subprojects or keep one app subproject
--use-defaultsDo not prompt for options that were not given
--overwriteAllow existing files in the directory to be overwritten

What gets generated

  • settings.gradle.kts: the root project name and the included app subproject.
  • app/build.gradle.kts: the Kotlin JVM and application plugins, mavenCentral() as repository, test dependencies, and application { mainClass = ... } pointing at the generated main class.
  • app/src/main/kotlin/... and app/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 init asks before continuing; --overwrite skips 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.kts under dependencies { implementation(...) }; ./gradlew dependencies shows 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.

Sources