Get started with Kotlin
Before you start working with Kotlin, make sure that the plugin is enabled. The plugin is bundled with IntelliJ IDEA and is activated by default. If the plugin is not activated, enable it on the Plugins page of the IDE settings Ctrl+Alt+S as described in Install plugins.
IntelliJ IDEA provides first-class support for Kotlin. It includes Kotlin-specific project templates, coding assistance, refactorings, debugging, analysis tools, and so on. Most of the Java tools are available for Kotlin, so, for example, if you know how to use Java debugger or refactorings, your experience will be enough to use these in Kotlin. In this topic, you will find the instructions to get started with Kotlin in IntelliJ IDEA.
Create a Kotlin project
From the main menu, select
.In the left-hand menu, select Kotlin.
Select the project template. The template defines the project structure and dependencies. The following project templates are available:
JVM
Console Application: console application with Kotlin/JVM. Use it for prototyping or testing purposes.
Multiplatform
Library: library for sharing common code among different platforms.
Native Application: application with Kotlin/Native that works as a standalone application under a specific platform.
Full-Stack Web Application: full-functional web application using Kotlin/JS for the frontend and Kotlin/JVM for the backend.
Kotlin/JS
Browser Application: frontend application with Kotlin/JS and non-Kotlin backend for browser. If you use Kotlin for backend, the better option is Full-Stack Web Application.
React Application: frontend application with Kotlin/JS and React UI framework for browser.
Node.JS Application: a standalone application with Kotlin/JS for the Node.js runtime.
Compose Multiplatform
Compose Desktop Application: a compose application targeting the desktop JVM platform (Windows, Linux, macOS).
Compose Multiplatform Application: Multiplatform (JVM/Windows, JVM/Linux, JVM/macOS, Android) Compose project with shared code in common modules.
Compose Web Application: a web Compose project for JS.
Select the build system that you are going to use in the project.
Specify the JDK that will be used in the project (version 1.8 or later is recommended). The JDK:
is essential for projects built with IntelliJ IDEA build system.
used for coding assistance in projects built with Gradle and Maven
If you don't have a JDK installed, you can download it right in the dialog.
Specify coordinates of the primary artifact: Group ID, Artifact ID, and Version. Not applicable for IntelliJ build system.
If you chose IntelliJ as the build system, specify the Kotlin Runtime library that will be used in the project.
Click Next to proceed to configuring the module structure. For detailed information, see New Project Wizard.
Mix Java and Kotlin in one project
You can call Java code from Kotlin and vice versa. This enables you to gradually transition a project to Kotlin or use both languages in parallel, for example, by using Kotlin for testing an existing Java codebase.
In order to start using Kotlin in your project, make sure that the Kotlin plugin is enabled and the Kotlin dependency is added to your project.
Add Kotlin dependency to an existing JVM project
Convert Java to Kotlin
IntelliJ IDEA allows you to automatically convert your Java code to Kotlin. The resulting code is not supposed to be perfect, however, it may be helpful in some situations.
If you are not satisfied with the result of conversion, you can roll it back with Ctrl+Z.
Paste Java code in a Kotlin file. In the dialog that appears, click Yes.
With a Java file open in the editor, go to main menu and select
or press Ctrl+Alt+Shift+K.