Adding Kotlin build-system to Sublime Text 3

Hello all, this is a small tip for all the Sublime Text lovers out there. Since there are no such plugin, this simple build tool will add a compile and run facility of Kotlin script from inside Sublime Text 3. 

Kotlin is the newest sensation among Android and Java developers. Since Google announced that they are officially adding Kotlin to the Android Studio, developers are flocking in to have a look at this new language. Though there are quite a number of apps out there developed with Kotlin, it is certainly a great news for all app-devs especially to those who have been waiting for something as-good as Apple’s Swift. Kotlin is lightweight, modern and way-easier than Java. The best thing about this language is that it is completely convertible and interchangeable with Java and run under JVM. Kotlin is developed by JetBrains, a company famous for making many successful IDEs.

Currently Kotlin can be used with IntelliJ IDEA and Eclipse. These IDEs have full support for Kotlin, and of coarse, they are huge in size. The reason to use Sublime Text is not only because we have limited disk-space and RAM to run bulky IDEs, its because we are really in love with this tiny editor. So let’s create a build system for Kotlin.

  1. Download the latest Kotlin compiler.  If you don’t already have JDK installed, install it now.
  2.  extract the ziped compiler to somewhere.
  3.  Install the Sublime Text 3 if haven’t already.  Go to Tools > Build-system > New Build System
  4. you will meet a blank file. Delete everything in it and paste these lines.
  5. This code is for windows. For linux change your "path/to/Kotlinc/bin/kotlinc" in line 2. You will also need to change \\\\ to / in line 2 and 12.

  6. Name the file kotlin.sublime-build and save it to ~sublime folder/Data/Packages/User/. In linux it should be in "/home/user/.config/sublime-text-3/Packages/User"
  7. Restart Sublime Text. Create a new files with these lines and save it with a .kt extension (ie. hello.kt)

Now use Ctrl+Shift+B to first compile and then run the code.

Don’t forget to install the Kotlin language package. It seems your compiler is a bit slow, why don’t you switch to Gradle continuous build system.

4 Comments

  1. Most Linux users can probably figure out what to do, but here it is step-by-step.
    $ sudo apt update
    $ sudo apt install default-jdk
    $ curl -s https://get.sdkman.io | bash
    $ sdk install kotlin
    $ source "/home//.sdkman/bin/sdkman-init.sh"

    Follow Sunbeam’s instructions for the build file, but use this instead
    {
    "cmd": ["/home//.sdkman/candidates/kotlin/current/bin/kotlinc", "$file", "-include-runtime", "-d", "$file_path/$file_base_name.jar"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "working_dir": "$file_path",
    "selector": "source.Kotlin",
    "variants": [
    {
    "name": "Run",
    "cmd": ["java", "-jar", "$file_path/$file_base_name.jar"]
    }
    ]
    }

  2. You didn’t mention in the article that you are using Windows. Where is the Linux version of the configuration file?

Leave a Reply

Your email address will not be published.

*

© 2017 ClubGIS

Theme by Anders NorénUp ↑

This work is licensed under Creative Commons.