Setting up
Kilua RPC supports different server-side frameworks - Ktor, Jooby, Spring Boot, Javalin, Vert.x and Micronaut - so you have to choose one of them for your needs. It's worth to mention, that common
and js
/wasmJs
code of your application are exactly the same for all servers, as well as the greater part of the actual service implementation for the jvm
target. The differences are tied to initialization code and additional server side functionalities (e.g. authentication).
Dependencies
You need JDK 21 to build Kilua RPC application. Your project should use standard Kotlin multiplatform layout, with separate sources sets for common
, jvm
and js
and/or wasmJs
code, located in separate directories: src/commonMain
, src/jvmMain
and src/jsMain
and/or src/wasmJsMain
. You can also declare a shared src/webMain
sources set if you want do develop for both js
and wasmJs
targets:
You should apply KSP Gradle plugin as well as Kilua RPC Gradle plugin, which is responsible for code generation and provides tasks for building and packaging your application.
You also need to add one of Kilua RPC modules to your common
dependencies. A range of modules are available for different servers and different configurations.
Development
During the development phase you compile and run js
or wasmJs
and jvm
targets separately.
Frontend
To run the frontend application with Gradle continuous build run one of these commands:
Backend
To run the backend application run one of these commands:
There are different levels of support when it comes to auto-reload. Javalin doesn't support auto-reload at all. Jooby, Vert.x and Micronaut have built-in auto-reload based on sources monitoring, so it works out of the box. In case of Ktor and Spring Boot auto-reload is based on the classpath monitoring, so you have to run another Gradle process for continuous build:
Production
Kilua RPC provides dedicated tasks to build and package complete application optimized for production, with js
or wasmJs
frontends:
The application "fat" jar will be saved in build/libs
directory (projectname-1.0.0-SNAPSHOT.jar
). You can run your application with thejava -jar
command.
Last updated