How to configure Kotlin in your project
Kotlin can be freely mixed with Java. That means that you can easily add Kotlin code to an existing Java project. All you need to do is create a new Kotlin file (*.kt) and tell the environment to use Kotlin. If you’re using IntelliJ IDEA, it can do this for you automatically.
The Kotlin plugin checks that all your modules containing Kotlin files are configured correctly. If they’re not, you will see the following notification in the upper left corner of the editor:
To configure them, click one of the links in the notification, based on what you need.
Targeting JVM Byte Code
If you want to compile Kotlin to JVM byte code, click on as Kotlin (Java) module. You’ll be prompted with the following dialog:
Here you can choose which modules need to be configured and a destination path to copy the library to.
You can either choose to copy the JAR library and store it under your project folder (optionally checking it in to VCS) or select Use library from plugin which will merely use the JAR bundled with the plugin in IntelliJ IDEA. However, the latter option means that your project will only work on machines where this plugin is installed.
Similar to above, you can then specify where you want the runtime files stored.
Using Maven or Gradle
If you use Maven or Gradle we have also great news: the Kotlin plugin now can configure your project using pom.xml or *.gradle files.
Once again, you need click the link in the notification, choose the modules to configure and the version of the Kotlin plugin (latest stable version or snapshot).
Configuration files for selected modules will be changed as described here.
If by chance you miss a notification, you can always access it via the Event Log in IntelliJ IDEA.
Also please note that the notification will appear only if you have Kotlin files under source root in your project.
For Gradle Users: Your Kotlin files should be under a source root named ‘kotlin’
Subscribe to Blog updates
Thanks, we've got you!
Gradle Kotlin DSL 1.0
This is a guest blog post from Paul Merlin software engineer for Gradle The recently released Gradle 5.0 includes the Gradle Kotlin DSL v1.0 which is now ready for widespread use. We want you to enjoy a build authoring experience with the benefits provided by Kotlin’s static type system in Inte…
Kotlin 1.3 Released with Coroutines, Kotlin/Native Beta, and more
You can read this blog post in other languages: Today we are releasing Kotlin 1.3 together with a set of accompanying libraries, build tools, and learning materials! We develop Kotlin to be a good tool for all application developers, at all scales and on all platforms. In Kotlin…
KotlinConf 2018 Announcements
In today's keynote at KotlinConf 2018 we made a series of announcements around releases, resources, and other things we've made available. For your convenience below is a brief summary of the announcements with the corresponding links for more information. Kotlin 1.3 hits RC Version 1.3 hits RC…