Hello, I am working on a Kotlin project with Ktor ...
# ktor
a
Hello, I am working on a Kotlin project with Ktor and Gradle, and it is divided into two apps. One is a REST API, and the other is a WebSocket chat. I want to share non-business code between these projects, such as Exceptions, StatusPages, Responses, JWT configurations, etc. What is the best way to do this?
a
You can share them through a shared module. For more information please read https://kotlinlang.org/docs/multiplatform.html
a
Okay, I got the idea of sharing a module. But how to implement it? How to share this module in my IntelliJ projects? For now, I have to separate server-side projects/apps where code is duplicated (for example, JWT plugin configuration). My goal is to have no duplicated code. At Kotlin multiplatform docs, I didn't find any information on how can I actually implement a shared module in my project. Could you provide me some extra information about it?
a
I think you should just add a new module to your project and include it your Gradle configuration. You then use it like any other dependency in your REST and websocket modules. It sounds like you already have a Gradle multi-project build set up, is that so?
a
No, for now, those are two independent projects
a
Then it’s going to be slightly more complicated. You need to publish your common dependency locally (and in your CI/CD pipeline if necessary), which is more a Gradle dependency management question. You should evaluate if it’s worth the effort to go through the hoops of maintaining a versioned dependency in your local artifact repository. There might be some way to set-up a multi-project build without actually having a project with multiple modules, but you’d have to investigate it yourself. If it’s at all plausible, having a normal Gradle multi-project is by far the easiest and least painful option.
a
Will this Gradle multi-module approach let me scale the chat-app separately to my rest-api-app?
a
Yes. Typically a multi-module project would be a single repository, but it doesn’t have to be so.