Sorry for the repost, I had asked this question a ...
# kotlin-native
j
Sorry for the repost, I had asked this question a while ago in #multiplatform but I think it might be more appropriate here. I'm getting the following warning in a multiplatform library with iOS support:
Copy code
A compileOnly dependency is used in the Kotlin/Native target 'iosArm64'
The
commonMain
source set indeed declares
kotlinx-serialization-json
as a
compileOnly
dependency. This is what I want for non-native targets (JVM, JS browser, JS node...) because I don't want to force this JSON-specific dependency onto users that want to use other serialization formats, but I do want to add a couple JSON-specific helper functions for ease of use if they do add the JSON dep on their end. So I have a couple questions: 1. is this actually a problem? I mean, by default it's supposed to compile the native targets to a
klib
(not a linked binary) so why is this a problem? Shouldn't it be a problem on the consumer side when actually building a final binary? 2. if it is a problem, how can I solve it? I tried to add this dependency as
implementation
inside the
iosMain
source set, but it doesn't seem to solve the warning. Is my only option to split my module into 2 modules, one with an
implementation
dependency on
kotlinx-serialization-json
and one without the dependency? I'm tempted to just disable the warning with
kotlin.native.ignoreIncorrectDependencies=true
but I'd like to understand better if it's really a problem first
e
https://youtrack.jetbrains.com/issue/KT-32476 I don't know how much of a problem it actually is
j
Thanks, yes I had seen that issue, but I'm trying to understand what can go wrong because of that. In the publication it seems the pom of my module doesn't have any mention of the compileOnly dependency, so I guessed that was fine. But a user opened an issue today, and I have a bad feeling that this might be the problem: https://github.com/joffrey-bion/krossbow/issues/231
FTR,
compileOnly
does seem to be the cause of the above bug on the consumer side of Krossbow. So it is indeed an actual problem. Apparently this is due to problems with caching on Native: https://youtrack.jetbrains.com/issue/KT-46377 A workaround on the consumer side is to disable caching:
Copy code
kotlin.native.cacheKind=none
But the best option is likely to avoid
compileOnly
altogether on library side, which is unfortunate.