KVision supports five server-side frameworks - Ktor, Jooby, Spring Boot, Javalin and Vert.x - so you have to choose one of them for your needs. It's worth to mention, that common and frontend targets of your application are exactly the same for all three servers, as well as the greater part of the actual service implementation in the backend target. The differences are tied to the actual framework build configuration and initialization code.
KVision full-stack applications utilize Kotlin multiplatform architecture (Kotlin 1.3 MPP). That's why you have to prepare the special Gradle configuration and the project layout. To start, it's best to just clone one of the template-fullstack projects from kvision-examples GitHub repository.
The application sources are split into three source sets -
backend, located in three directories:
src/backendMain. The requirements and dependencies for the build process are the same as mentioned in Part 1 of this guide.
Since version 2.0 you can use KVision compiler plugin to generate code in the common and frontend modules. You can still create this code by hand, but it's definitely easier to use the plugin.
During the development phase you compile and run frontend and backend targets separately.
To run the frontend application with Gradle continuous build enter:
./gradlew -t frontendRun (on Linux)gradlew.bat -t frontendRun (on Windows)
To run the backend application enter:
./gradlew backendRun (on Linux)gradlew.bat backendRun (on Windows)
There are different levels of support when it comes to auto-reload. Javalin doesn't support auto-reload at all. Jooby and Vert.x 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:
### Ktor or Spring Boot./gradlew -t compileKotlinBackend (on Linux)gradlew.bat -t compileKotlinBackend (on Windows)
After both parts of your application are running, you can open http://localhost:3000/ in your favorite browser. Changes made to your sources (in any source set) should be automatically applied to your running application.
To build complete application optimized for production run:
./gradlew -Pprod=true clean jar (on Linux)gradlew.bat -Pprod=true clean jar (on Windows)
The application jar will be saved in
build/libs directory (
projectname-1.0.0-SNAPSHOT.jar). You can run your application with the
java -jar command.
java -jar build/libs/projectname-1.0.0-SNAPSHOT.jar