Working with Compile Time Generated Code

I want to:

  • compile dynamically generated Kotlin code perhaps using Kotlin Poet and
  • followed by minimising the generated code with R8 and
  • then load the compiled code for execution

How would I go about achieving the above tasks?

Since compiling Kotlin is expensive, it’s usually a lot more efficient to skip that step by generating bytecode with ASM or similar: