How to Enable Kotlin 1.3 Inline Classes Today

Are you ready to start exploring inline classes? Since they’re still an experimental feature, you’ll need to take a few extra steps to enable them in your project. It’s not difficult to set up, but there are a few things to watch out for. This guide will help you navigate those issues so that you can start playing with Kotlin 1.3 and inline classes today.

1. Set the Kotlin Plugin Channel

The Kotlin plugins for your IDE are published in different update channels. By default, the update channel is going to be set to Stable, which is what you probably want most of the time. But to use inline classes and other 1.3 features, you’ll want to set it to use an early access version of 1.3.

To set this, open the Tools menu, and then go to Kotlin > Configure Kotlin Plugin Updates.

Set the update channel to Early Access Preview 1.3, and click the Install button. Once it’s done installing, it’ll tell you that the plugin will be activated after you restart, so restart the IDE at that point.

2. Create a New Project

Create a new project, and of course select:

Kotlin (Java) if you’re using Gradle in IDEA

kotlin-archetype-jvm if you’re using Maven in IDEA

Include Kotlin support if you’re in Android Studio

Walk through the rest of the setup wizard.

3. Add the repository

The Kotlin build tool plugins and standard library for 1.3 aren’t published to the same repositories as the stable versions are, so you’ll need to update your build script so that it knows where to find them.

Gradle in IDEA

If you’re using a Gradle build in IDEA, and you created the project with version 1.3 of the Kotlin plugin installed, your settings.gradle and build.gradle files should already include the right repository. If that’s the case you can skip this step.

Gradle in Android Studio

For Android Studio, on the other hand, the repository doesn’t appear to be added automatically. You’ll know it because you’ll get a message like this:

Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:1.3-M1.

… or this …

Failed to resolve: org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3-M1

To fix this, add a repository that points to http://dl.bintray.com/kotlin/kotlin-eap. For example:

Be sure to add this to both the regular repository section (e.g., under allprojects, depending on your build) and the buildscript section. Here’s an example of a top-level build.gradle file for an Android project that includes the correct repository:

Just in the IDE

You can also set this just in the IDE with the Additional command line parameters field of the Kotlin Compiler settings page, or on a per-module basis by opening the Project Structure menu, and expanding the module tree until you get to Kotlin.

Other Stuff that Might Happen

Language Version

If you’re converting a 1.2 project to use 1.3, you might end up with an error message like this:

The feature “inline classes” is only available since language version 1.3

In this case, you probably still have the Kotlin plugin set to a 1.2 version. You can update it to a 1.3 build (such as 1.3-M1). Or if you really want to keep it on 1.2, you could set the languageVersion, like this:

Coroutines

If you’re using coroutines, you’ll want to make sure you’re using a version that’s compatible, or else you’ll get this message:

Library should be updated to be compatible with Kotlin 1.3

It’s easily fixed by updating the dependency:

compile 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.24.0-eap13'

There’s even a handy-dandy intention action (i.e., quick fix) for both Gradle and Maven - just press Alt+Enter.

And You’re Done!

After following these steps, you should be able to start using inline classes - and explore other Kotlin 1.3 features! If you have any trouble with these instructions, or discover anything else that’s required for your installation, let me know!