'Standalone' common library

Hello o/

I wanted to start a new multi-platform project which will include, at first, a Ktor server and a JS webapp.
Most of the code can be in the common module, since the specifics will probably only be database engine, testing framework, ui-related classes and such.
For now, I only know of two actual modules: JVM (Or Native, not sure yet) and JS. But then I started to wonder: what if someone wants to create an iOS or Android version ?
My problem is, I don’t really want to put all that in one single repository. The ideal case would be to be able to define my common module as standalone, publish it on Bintray/whatever, and let people reference it as an expectedBy() dependency so that they can benefit from the common code and only focus on their module, in whatever repo they want, without the need to give them access to my code or have them pull a whole bunch of seemingly unrelated stuff (i.e why would the Android app dev need to know about / have access to the Webapp implementation?)

I’ve been able to create a ‘standalone’ common project, which builds, but IntelliJ’s linter is not happy with my expect declarations not having any actual counterparts. Since my gradle build doesn’t know anything about the modules hosted in some other repo.

So the question is: is this possible? Am I simply doing something wrong, or is it plain impossible?

NB: I understand the concept of mpp when it comes to a project the team knows which actual platform-specific modules it wants to implement. Even for multi-platform libraries. Kotlin MPP works really well for that. My question is really how to benefit from Kotlin common, and share this common module so other, unrelated people, can create their own implementation without managing the rest?

This is what I get in IntelliJ for my common module:

Build is fine, but the linter, not so much ~

Publishing a common module and implement the actual parts in another project is impossible, for now. Kotlin mulitplatform is still in early development and only released in an alpha stage right now. I am pretty sure this will be a feature before it’s final release, but it’s not possible right now.

The linter warning is kinda right. Although the build does not fail (in gradle) it does not create any useable output, mabye it should fail in gradle as well. The fact is, for mpp to work you need at least on module with actual implementations.

1 Like

Alright yeah, that is what I suspected.

I really hope that’s on the roadmap! I find Kotlin common or more generally MPP fantastic, but that’s the last roadblock I can think of.

Thanks for confirming it!

Yes, it’s a known limitation, we’re considering fixing it at some point. You can vote/follow https://youtrack.jetbrains.com/issue/KT-30088 for updates.

2 Likes