if I have a kotlin2js frontend project, and a kotl...
# javascript
y
if I have a kotlin2js frontend project, and a kotlin2js backend projects, both in gradle in the same repo, is there a way to reuse a data class in both projects from a shared gradle module?
Copy code
- root
    - module1
        - build.gradle
    - module2
        - build.gradle
    - sharedmodule
        - src
            - SomeDataClass.kt
        - build.gradle
    - build.gradle
In the above example, I'd like to use
SomeDataClass
in module 1 and module 2 without having to set up a kotlin multiplatform project cc @Zachary Smith
n
Presumably you want to share some business logic. In that case it would be much better to have everything in a Kotlin MPP (Multi Platform Project - https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html), and have the business logic (incl models) that will be shared in a Common module.
z
that definitely makes sense. however for this project we were just looking to explore how we can use kotlin to interact with the JS eco system. and since we were only targeting JS, we thought we could get away with just sharing the code like a standard multi module project.
y
To further add onto Zach's point: Having a shared module on the jvm is trivial, just add two gradle modules and have one depend on the other. Having a shared module in js is not. So far the only solution that exists is to make a kotlin mpp project. Sharing code in js should be analogous to sharing code in jvm. If the jvm only multi module project does not require k mpp, then a js only multi module project should not require k mpp either If that's not possible at this point in time, that's one story. However if the suggested way of sharing js code between other js modules is to make a multi platform project, I disagree and I think the developer experience can be improved
k mpp makes much more sense if the codebase spans across multiple runtimes/platforms. our use case is on a single runtime/platform
d
You should be able to depend on
project("projectName")
👍 1