IntelliJ IDEA 2024.2 Help

Get started with Kotlin

Before you start working with Kotlin, make sure that the Kotlin 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 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

This is a general-purpose project without specific frameworks. You will be able to add the necessary frameworks and technologies later at any time.

  1. On the Welcome screen, click New Project. Alternatively, in the main menu, go to File | New | Project.

  2. From the list on the left, select Kotlin.

  3. Name the new project and change its location if necessary.

  4. Select the Create Git repository checkbox to place the new project under version control.

    You will be able to do it later at any time.

    Creating a new project
  5. Select the IntelliJ build system. It's a native builder that doesn't require downloading additional artifacts.

    If you want to create a more complex project that needs further configuration, select Maven or Gradle. For Gradle, choose a language for the build script: Groovy or Kotlin.

  6. From the JDK list, select the JDK that you want to use in your project.

    If the JDK is installed on your computer, but not defined in the IDE, select Add JDK and specify the path to the JDK home directory.

    If you don't have the necessary JDK on your computer, select Download JDK.

  7. Enable the Add sample code option to create a file with a sample Hello World! application.

    You can also enable the Generate code with onboarding tips option to add some additional useful comments to your sample code.

  8. Click Create.

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

  • If your project uses the IntelliJ IDEA build tool, it adds the Kotlin dependency automatically. The first time you create a Kotlin file in the project, a notification appears to confirm that the Kotlin configuration is ready.

  • For other build tools, follow the steps in:

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 the main menu and select Code | Convert Java File to Kotlin File or press Ctrl+Alt+Shift+K.

If you would like to get all the Kotlin news right in your inbox, make sure to subscribe to the Kotlin newsletter.

Last modified: 11 October 2024