a pleasant surprise - to consume a KMP library fro...
# scripting
p
a pleasant surprise - to consume a KMP library from a script, I didn't have to add
-jvm
- just
@file:DependsOn("it.krzeminski:snakeyaml-engine-kmp:3.1.0")
works now 🙂
mind blown 2
nono 2
đŸ€” 1
m
Wait what how is that remotely possible?
Unless KGP multiplatform creates maven compatible publications now?
p
I haven't dig deeper into why it works now, good question
m
I don't really see JetBrains adding supporte for Gradle metadata to the scripts resolver...
p
exactly
the worst case would be that it's a coincidence/non-determinism
But looks like the publication is compatible still đŸ€”
Nope
Copy code
$ unzip ../snakeyaml-engine-kmp-3.1.0.jar
Archive:  ../snakeyaml-engine-kmp-3.1.0.jar
   creating: META-INF/
  inflating: META-INF/MANIFEST.MF
  inflating: META-INF/kotlin-project-structure-metadata.json
   creating: commonMain/
   creating: commonMain/default/
  inflating: commonMain/default/manifest
   creating: commonMain/default/linkdata/
  inflating: commonMain/default/linkdata/module
   creating: commonMain/default/linkdata/package_it.krzeminski.snakeyaml.engine.kmp.api/
  inflating: commonMain/default/linkdata/package_it.krzeminski.snakeyaml.engine.kmp.api/00_api.knm
  inflating: commonMain/default/linkdata/package_it.krzeminski.snakeyaml.engine.kmp.api/01_api.knm
  inflating: commonMain/default/linkdata/package_it.krzeminski.snakeyaml.engine.kmp.api/02_api.knm
  inflating: commonMain/default/linkdata/package_it.krzeminski.snakeyaml.engine.kmp.api/03_api.knm
There's no JVM bytecode in there
p
it's a miracle
😂 1
m
Maybe JetBrains added a specific case. So that they don't have to support the full metadata madness but it works for this simple case đŸ€·
Or it's just a miracle 🙂
p
So the big question is: does it work in every case, and can it be relied upon going forward? If yes, it probably should be documented and announced somewhere
nod 1
m
Can confirm it works here as well 🎉
Mmm not at runtime... Only in the IDE...
đŸ€” 1
Copy code
@file:DependsOn("com.apollographql.apollo:apollo-api:4.1.1")

println(com.apollographql.apollo.api.ApolloResponse::class)
output:
Copy code
$ kotlin /Users/martinbonnin/Downloads/tmp/toto.main.kts
toto.main.kts:5:13: error: unresolved reference 'apollographql'.
println(com.apollographql.apollo.api.ApolloResponse::class)
p
For me, at runtime, both locally and on GitHub
m
What version are you using?
Copy code
martinbonnin:~/Downloads/tmp$ kotlin -version
Kotlin version 2.1.10-release-473 (JRE 22.0.2+9)
martinbonnin:~/Downloads/tmp$ kotlin /Users/martinbonnin/Downloads/tmp/toto.main.kts
toto.main.kts:5:9: error: unresolved reference 'it'.
println(it.krzeminski.snakeyaml.engine.kmp.api.ConstructNode::class)
Script is:
Copy code
#!/usr/bin/env kotlin

@file:DependsOn("it.krzeminski:snakeyaml-engine-kmp:3.1.0")

println(it.krzeminski.snakeyaml.engine.kmp.api.ConstructNode::class)
j
Unless KGP multiplatform creates maven compatible publications now?
I doubt, the manual fix to allow not needing -jvm on Maven is still mandatory
m
Yea, I can't make it work at runtime. Only the IDE seems to recognize it here
p
Kotlin 2.1.0, newest one on GitHub Actions
a
my guess would be it's resolving something from Maven Local?
p
Hmm, Maven Local is unlikely to have any role on a GitHub Actions worker, right? In this case running the script is the first thing I do on the worker, so ML should be empty
here's an experiment I did: 1. Purge Maven Local (
rm -rf ~/.m2/repository
) 2. Call the script. 3. Check what sits in
find ~/.m2/repository/it/krzeminski
for me it's:
Copy code
/Users/piotr/.m2/repository/it/krzeminski
/Users/piotr/.m2/repository/it/krzeminski/snakeyaml-engine-kmp-jvm
/Users/piotr/.m2/repository/it/krzeminski/snakeyaml-engine-kmp-jvm/3.1.0
/Users/piotr/.m2/repository/it/krzeminski/snakeyaml-engine-kmp-jvm/3.1.0/snakeyaml-engine-kmp-jvm-3.1.0.pom
/Users/piotr/.m2/repository/it/krzeminski/snakeyaml-engine-kmp-jvm/3.1.0/snakeyaml-engine-kmp-jvm-3.1.0.pom.sha1
/Users/piotr/.m2/repository/it/krzeminski/snakeyaml-engine-kmp-jvm/3.1.0/snakeyaml-engine-kmp-jvm-3.1.0.jar
/Users/piotr/.m2/repository/it/krzeminski/snakeyaml-engine-kmp-jvm/3.1.0/snakeyaml-engine-kmp-jvm-3.1.0.jar.sha1
/Users/piotr/.m2/repository/it/krzeminski/snakeyaml-engine-kmp-jvm/3.1.0/_remote.repositories
/Users/piotr/.m2/repository/it/krzeminski/snakeyaml-engine-kmp
/Users/piotr/.m2/repository/it/krzeminski/snakeyaml-engine-kmp/3.1.0
/Users/piotr/.m2/repository/it/krzeminski/snakeyaml-engine-kmp/3.1.0/snakeyaml-engine-kmp-3.1.0.jar.sha1
/Users/piotr/.m2/repository/it/krzeminski/snakeyaml-engine-kmp/3.1.0/snakeyaml-engine-kmp-3.1.0.jar
/Users/piotr/.m2/repository/it/krzeminski/snakeyaml-engine-kmp/3.1.0/_remote.repositories
/Users/piotr/.m2/repository/it/krzeminski/snakeyaml-engine-kmp/3.1.0/snakeyaml-engine-kmp-3.1.0.pom.sha1
/Users/piotr/.m2/repository/it/krzeminski/snakeyaml-engine-kmp/3.1.0/snakeyaml-engine-kmp-3.1.0.pom
I grepped over files in
/Users/piotr/.m2/repository/it/krzeminski/snakeyaml-engine-kmp
and there's no mention of
jvm
also interesting: when I call the script and then periodically, quickly list contents of Maven Local, first
snakeyaml-engine-kmp-jvm
appears, then after several seconds comes
snakeyaml-engine-kmp
I know what's happening...
github-workflows-kt
which is a purely JVM lib depends on
snakeyaml-engine-kmp-jvm
đŸ€Šâ€â™‚ïž
so ideally Kotlin should complain that it doesn't know how to resolve
@file:DependsOn("it.krzeminski:snakeyaml-engine-kmp:3.1.0")
but it just doesn't, and the script works as if this line wasn't there (the multiplatform artifact of
snakeyaml-engine-kmp
is fetched even though Kotlin Scripting cannot really use it)
snakeyaml-engine-kmp
is an
implementation
kind of dependency in
github-workflows-kt
(not
api
), so it kind of leaks from there unintentionally: https://github.com/typesafegithub/github-workflows-kt/blob/32b177e5704c8db43e6fd19ab30f634d7dcd03d2/github-workflows-kt/build.gradle.kts#L24
and indeed, in the POM, it's marked with
<scope>runtime</scope>
m
Kotlin should complain that it doesn't know how to resolve
@file:DependsOn("it.krzeminski:snakeyaml-engine-kmp:3.1.0")
but it just doesn't
Kotlin knows how to resolve that. It resolves to a jar with no JVM bytecode (only Kotlin metadata). So it doesn't compile. But technically the coordinates are resolved.
👍 1
p
ah yes, so it's seen like an empty JAR, even if Kotlin Multiplatform was taken out of the picture
m
Exactly, which adds to the confusion...
I'm now team "no Gradle metadata". I'd rather have multiple publications but keep compatibility with other tools
Looks like the Kotlin team is taking the same direction and thinking about publishing "fat" KMP artifacts
a