kotlinshelldependency-managementki

How can I load external dependencies using ki (Kotlin Interactive Shell)?


I am using using Ki (Kotlin Language Interactive Shell) to run Kotlin interactively on the shell, and I came across the need to load a 3rd-party library so I can script something quick. For example, let's say I want to use turtle to run a simple ls command:

shellRun("ls")

How can I set my ki shell in a way that turtle becomes available?


Solution

  • You will need to use the :dependsOn command:

    [0] :dependsOn com.lordcodes.turtle:turtle:0.8.0
    [1] com.lordcodes.turtle.shellRun("ls")
    

    Ki allows you to download dependencies in runtime using Maven coordinates.

    You can see the source code here: org.jetbrains.kotlinx.ki.shell.plugins.DependsOnCommand