The Kotlin team have created an Eclipse plugin for working with Kotlin projects in eclipse. It is hosted at github: https://github.com/JetBrains/kotlin-eclipse. This page describes how to work with Spring Boot apps written in Kotlin in Spring Tool Suite. Currently there are a few rough edges and this should help you work through them and understand the current limitations - it is a work in progress. The instructions below should work with STS 3.7.2 and later.
The nightly builds of the Kotlin Eclipse plugin are available from this update site:
Note:Currently (on Feb-18-2016) the nightly builds include some important fixes that make the STS experience smoother, so you may want to install from this update site.
The latest stable release update site is here:
It is also on the eclipse marketplace: https://marketplace.eclipse.org/content/kotlin-plugin-eclipse
Just install like any other plugin using the standing install dialog available via
Creating a sample project
Spring Starter Project Wizard
With the plugin installed you can immediately start creating Kotlin projects but if you want to get going really quickly with a Spring Boot application, you might want to use the Spring Starter wizard:. As you can see below it is already enabled with a Kotlin language choice:
Let's try using it now. Open the wizard, change the language to Kotlin and then press Next, on the subsequent page let's add the Web starter and press Finish:
When importing finishes, you may be left with an error on the maven pom:
This is kotlin issue 8401. As of Feb-18-2016 it has been fixed in nightly builds (v0.6.0.v20160218) but the fix hasn't made it to the stable releases yet. You can update to a nightly build or use a quick fix for now (either the quick fix to ignore in preferences or ignore in pom would be fine, although ignoring in pom may need you to do a action on your project). With that gone the project should be building cleanly.
What about Gradle
You can select the gradle build option on the Spring Starter wizard (either the STS or Buildship Gradle), but once the project is imported you will need to manually add the kotlin nature. Select the project, right click. Once that is done you will be able to work on it and run it as shown below.
Let's create a new data class called com.example.Greeting. Use the Kotlin Class wizard accessible through:
And then let's define the data class:
Use the wizard to also create a com.example.GreetingController class:
Running the app
The simplest way to run the app is to select the DemoApplication.kt file in the package explorer, right click. It should then be accessible via your browser:
It is important to note that you cannot directly the use the
You can then use that launch config just like any other.
And Cloud Foundry?
It is possible to deploy from the UI to Cloud Foundry but it isn't currently as streamlined as we would like. Here is a process that works right now:
Download STS: https://spring.io/tools/sts/all
STS Issue tracker: https://issuetracker.springsource.com/browse/STS