https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
r

rsetkus

10/30/2020, 9:16 PM
Hi. Not sure if multiplatform channel is the right place and even not sure if that is possible. So, I am generating Kotlin response/request data classes used by Ktor. I'd like to keep them separate from common module. Created another module and included
api(project(":generatedapi"))
it as a dependency to common module. It compiles and builds successfully but when I publish the project as a library, those generated classes are not included so clients which are using multiplatform library cannot access them. Does anybody tried to achive something similar like this or maybe know a way how to expose dependency classes to clients? Thanks.
b

Big Chungus

10/30/2020, 9:24 PM
Either publish that module as well or add it as implementation
r

rsetkus

10/30/2020, 9:38 PM
@Big Chungus when say 'add it as implementation' you mean dump generated classes into common module?
b

Big Chungus

10/30/2020, 9:39 PM
No, i mean replace api to implementation on that dependency snippet you've sent
r

rsetkus

10/30/2020, 9:45 PM
Copy code
Cannot access class 'xx.yy.DataClass. Check your module classpath for missing or conflicting dependencies
b

Big Chungus

10/30/2020, 9:46 PM
Is that from the lib consumer?
r

rsetkus

10/30/2020, 9:46 PM
Getting this error on client side on attempt to use a class
Yeah
b

Big Chungus

10/30/2020, 9:47 PM
In that case you need to make your lib fat-ish jar that includes that module explicitly
Here's an example
And here
👍🏻 1
Second example is better suited to you. First one is embedded kotlin js as webjar
r

rsetkus

10/30/2020, 10:04 PM
Yeah, maybe the second example is something I am looking for. Will give a try. Ačiū
Not sure why but
jar
task is not found in my main multiplatform module. Instead used
jvmJar
and that worked fine. That works for Android, but I suppose I'd get the same issue for iOS. 🤔
b

Big Chungus

10/30/2020, 11:39 PM
You will. In this case why not just publish your internal module?
r

rsetkus

10/31/2020, 7:26 AM
But client/consumer would need to include (specify in dependencies) both libraries, wouldn't it?
b

Big Chungus

10/31/2020, 11:07 AM
Nope
Gradle/maven would download that internal dependency as transitive
r

rsetkus

10/31/2020, 5:16 PM
This is the thing. I published the other module too. Also, I can see that on client/consumer app's dependency tree, library is pulled as transitive dependency but still on client/consumer side I am getting error
Copy code
Cannot access class XXX Check your module classpath for missing or conflicting dependencies
b

Big Chungus

10/31/2020, 5:21 PM
Is your class public?
r

rsetkus

10/31/2020, 5:23 PM
Yes, correct. It is public.
b

Big Chungus

10/31/2020, 5:27 PM
Then I'm out of ideas. Can't help you more without seeing the actual code :/
r

rsetkus

10/31/2020, 5:31 PM
No worries. I'll try to make SSCCE (a Simple, Self-Contained, Correct (Compilable), Example) and publish it on github, for instance.
b

Big Chungus

10/31/2020, 5:33 PM
Tbh, I'm only interested in your gradlefiles and class signature. So if you could remove all your source code and publish that I could have a proper look
r

rsetkus

10/31/2020, 6:43 PM
Made gist files first. Let me know if you more context.
b

Big Chungus

10/31/2020, 6:44 PM
Can you make a proper git repo replicating your project structure? Will have a look at that first thing tomorrow
r

rsetkus

10/31/2020, 6:48 PM
Yeah, sure. No problem. Will post a link here.
b

Big Chungus

10/31/2020, 6:51 PM
Hold on. I see you now have everything as implementation. Can you try changing all dependencies to api and see if that works?
r

rsetkus

10/31/2020, 8:04 PM
Yeah, that worked. 🎉 Changed absolutely all
implementation
to
api
. I used
api
before but only for the other internal module and that didn't work.
b

Big Chungus

10/31/2020, 8:16 PM
Great! Api didn't work before because you weren't publishing the internal module
Api dependencies - transitive dependencies that gradle will download for the consumer Implementation dependencies - provided dependencies that gradle expects to already be on the classpath
r

rsetkus

10/31/2020, 8:20 PM
I see! Yeah, probably you're right. then I used
api
before, I didn't publish it at that time. Thanks a lot! I owe a 🍺 🙂
4 Views