Setting up

KVision supports three server-side frameworks - Ktor, Jooby and Spring Boot - 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 - common, frontend and backend, located in three directories: src/commonMain src/frontendMain and src/backendMain. The requirements and dependencies for build process are the same as mentioned in Part 1 of this guide.

Development

During the development phase you compile and run frontend and backend targets separately.

Frontend

To run the frontend application with Gradle continuous build enter:

./gradlew -t frontendRun                                (on Linux)
gradlew.bat -t frontendRun                              (on Windows)

Backend

To run the backend application enter:

./gradlew backendRun                                    (on Linux)
gradlew.bat backendRun                                  (on Windows)

All three frameworks have auto-reload feature, but only Jooby is watching for changes directly in the source code. 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 backendMainClasses                        (on Linux)
gradlew.bat -t backendMainClasses                      (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.

Production

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 thejava -jar command.

java -jar build/libs/projectname-1.0.0-SNAPSHOT.jar

Last updated