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

william

03/06/2021, 2:18 PM
anyone have an example of using
atomicfu
in a multiplatform project for common code? having some trouble with it and could use a reference project
o

Oleg Yukhnevich

03/06/2021, 3:33 PM
w

william

03/06/2021, 5:09 PM
thank you. applying the plugin was throwing an error, but just using the dependency in the commonMain source set is working
o

Oleg Yukhnevich

03/06/2021, 7:05 PM
note: plugin should be added to classpath in root module to support auto-dependencies
e

eygraber

03/08/2021, 12:39 PM
I have some code that's set up similarly to rsocket. There's a common module (
:core
) that has the atomicfu plugin, and another module (
:sample
) that depends on it, but does not use the plugin or declare a dependency on atomicfu. At runtime, when
:sample
invokes code from
:core
that uses atomicfu internally, it crashes with
NoClassDefFoundError: Failed resolution of: Lkotlinx/atomicfu/AtomicFU
The only way to fix that is to add the atomicfu plugin to
:sample
but i don't want to impose that on everyone that has a dependency on
:core
(it's part of a library). I know this isn't the case with libraries like coroutines or rsocket, so if you have any ideas that would be helpful.
I ended up just adding
api("org.jetbrains.kotlinx:atomicfu:0.15.1")
to the
:core
module
w

william

03/10/2021, 1:44 PM
@eygraber the consumers of core should only need
api
if your core module exposes something from atomicfu
e

eygraber

03/10/2021, 1:53 PM
It doesn't expose anything but it was the only way to get it to work without explicitly depending on atomicfu from the consumer. I made a bunch of changes to Gradle since then so I'll try again.
w

william

03/10/2021, 11:21 PM
interesting 🤷
193 Views