i am working on a simple kmp library template. in ...
# multiplatform
c
i am working on a simple kmp library template. in another kmp project (see "korpus" link) that consists of a jvm, common an js module to build a web app, i am able to use jvm dependency successfully. for some reason i am not able to call code from my library in common module. when i want to use the js publish of my library in the js module i get following error:
Copy code
* What went wrong:
Could not determine the dependencies of task ':kotlinNpmInstall'.
> Could not resolve all dependencies for configuration ':client-kt:jsNpmAggregated'.
   > Could not find codes.draeger:kotlin-library-template-core-js:0.1.0-SNAPSHOT.
     Searched in the following locations:
       - file:/Users/A200296237/.m2/repository/codes/draeger/kotlin-library-template-core-js/0.1.0-SNAPSHOT/maven-metadata.xml
       - file:/Users/A200296237/.m2/repository/codes/draeger/kotlin-library-template-core-js/0.1.0-SNAPSHOT/kotlin-library-template-core-js-0.1.0-SNAPSHOT.pom
       - <https://repo.maven.apache.org/maven2/codes/draeger/kotlin-library-template-core-js/0.1.0-SNAPSHOT/maven-metadata.xml>
       - <https://repo.maven.apache.org/maven2/codes/draeger/kotlin-library-template-core-js/0.1.0-SNAPSHOT/kotlin-library-template-core-js-0.1.0-SNAPSHOT.pom>
     Required by:
         project :client-kt
what am i doing wrong? here is my library template code: https://github.com/christian-draeger/kotlin-library-template code where i tryed to use it: https://github.com/christian-draeger/Korpus (client-kt) module in jsMain dependencies
c
You don’t target
js
in your template project.
c
where and what do i need to do to target it?
c
also in terms of “how to apply the same plugins in gradle” this is a bad idea, you should write a convention plugin. https://docs.gradle.org/current/samples/sample_convention_plugins.html
👍 1
c
i just added js as you proposed. i now can use my lib in js, jvm and common 🥳 but i get following warning when building the lib template
Copy code
Not choosing any of them will be an error in the future releases.
kotlin {
    js {
        // To build distributions for and run tests on browser or Node.js use one or both of:
        browser()
        nodejs()
    }
}
which should i choose in my case?
c
depends on what you are targeting again. is it a library for a browser or nodeJs? that influences what API’s that are available. node does not have any i.e “DOM” Api’s, on the other hand browser does not have any i.e. “File” API’s.
c
ok i see. yeah since it is a template project for actual libraries I don’t know now. 1 thing I have in my mind will be pure common code. Maybe stupid question but what would I need to choose if I have a library that is pure kotlin common source but maybe uses some kotlinx library as dependencies? No browser nor node api involved. In this case it doesn’t matter what to choose as JS target, but one needs to be selected?
e
it affects how your tests are run. if you expect downstream consumers on both nodejs and browser, then add both so you test both
👍 1
c
You never publish a pure „common“ library. You can only publish those targets you specify. And then others can consume your library if they target the same platforms (or a subset). So if you then add a dependency to your library the same affects you - the dependency also needs to provide libraries for the platform you target.
c
Ok makes sense, Thx for explanation. 🙂 But this in turn means, if my library is pure kotlin code it would be generally a good idea to target as many targets as possible to make a library usable everywhere and only exclude targets if they would need some actual implementation per platform where it makes no sense for some reason?
c
Exactly 👍🏻