Using Kotlin to offer easy plugin system


#1

Dear Kotlin developers, community,

I’m about to use Kotlin to offer possibility to write plugins/scripts for a system. I’m working on a simple home automation system (for my own home).

The requirements are:

  • easy to understand language ( Kotlin fulfils this pretty well )
  • dynamic detection and compilation of new classes (im not sure, probably i need to implement this part)

My base idea is reduce the problem to

  • having sensors/switches/etc as simple data classes implemented in Kotlin
  • data classes persisted
  • receiving data from external systems using the plugins implemented by the user (me)
  • reacting on data change using plugins implemented by the user (me)

The main idea is pretty close to the solution OpenHab offers, but i woul like to

  • avoid implementing a custom language/interpreter for my scripts
  • make it fast and simple
  • offer java compatibility on code and dependency level

The question is you see this feasible or im completly off?


#2

I think You can use kotlin for that prupose. I am creating kotlin source files at runtime and compile them with the embedded compiler and load the result in its own classloader. this works just fine.
you may have a look at cedric beusts kobalt, which also compiles kotlin files at runtime.


#3

Like @svd said, Kobalt compiles files at runtime so that might be helpful to you.

Another important aspect is the plug-in architecture, which is based on contributors. A Kobalt plug-in is made of multiple contributors and Kobalt calls into them in order to fetch information supplied by plug-ins. Plug-ins never call into Kobalt, something I think is critical to maintain a clean separation of API / plug-ins.

Here is the plug-in documentation:

http://beust.com/kobalt/plug-in-development/index.html