Creating a Spring Shell with Kotlin

Spring Shell - The Spring Shell project provides an interactive shell that allows you to plugin your own custom commands using a Spring based programming model.

In this post we’ll use Gradle 4.4 to build a Spring Shell coded with Kotlin 1.2.

Setup Gradle build

The initial setup of the build scripts is based on Using Gradle.

Within the build.gradle we specify the Kotlin Gradle Plugin with:

plugins {
    id "org.jetbrains.kotlin.jvm" version "1.2.0"

and add the required dependencies:

dependencies {

    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    compile "org.jetbrains.kotlin:kotlin-reflect"


Note: The additional kotlin-reflect is needed to avoid BeanCreationException caused by NoClassDefFoundError (KClasses).

Empty PlanetsShell

We boot the PlanetsShell with this small main class in src/main/kotlin:


import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication

open class PlanetsShell {

fun main(args: Array<String>) {, *args)

Build and run Planets Shell

Nothing special to build our first Spring Shell project…

$ ./gradlew clean build

and run the PlanetsShell:

$ java -jar build/libs/planets-shell.jar
2017-12-12 23:52:53.426  INFO 49791 --- [           main]         : Started PlanetsShellKt in 13.218 seconds (JVM running for 13.79)

Let’s add some commands…stay tuned.

Show Comments