STEM with Python – Part 13: Kotlin Compiler Automation

Automate everything!

Here’s another Python automation series on Linux. This time, you can automate the Kotlin compiling process with python script. Enjoy!!

This is another Python automation program I wrote on my home Linux server. As you may know, I’ve been learning Kotlin by myself to build my second Android app that’s going to be built with Jet-Pack.

For mastering Kotlin’s very basics, I was writing code, debug, and compiled it on the server. However, as I mentioned in my first Kotlin series, the compiling command, kotlinc, requires lots of options and it’s a repetitive and time-wasting activity – so, why not write a Python script to make it automotive?

Here’s the code:

import subprocess

def kotlinCompiler(file_name: str):
    result = subprocess.run(["kotlinc", file_name + ".kt", "-include-runtime", "-d", file_name + ".jar"], 
    shell=False, stdout=subprocess.PIPE)
    print(result.stdout.decode())

fileName = input("What's the file name? ")
kotlinCompiler(fileName)

And here’s the executed result:

$ python3 kotlinc.py
What's the file name? hello

Easy and fun. isn’t it?

What’s interesting about learning to code is that for mastering another coding language and making the learning process easier, you can actually take advantage of your knowledge of another language’s powerful features.

My Kotlin learning journey is now merging together with Pythion in that sense.

Keep learning, keep growing!

Leave a Reply