Friends, I beseech your wisdom. :sweat_smile: We'v...
# multiplatform
p
Friends, I beseech your wisdom. 😅 We've upgraded our multiplatform library to use Kotlin 2.0.0 and everything went smooth. However, when running
./gradlew publishKotlinMultiplatformPublicationToMavenLocal
we get a mere
daflkt-0.2.0.jar
with mere 647 bytes (containing only
META-INF/MANIFEST.MF
and
META-INF/kotlin-project-structure-metadata.json
). When using
publishJvmPublicationToMavenLocal
, we get an actual
daflkt-0.2.0.jar
with 20kb. My (newbie) question is, since our project builds for JVM only (so far), shouldn't we get the same
.jar
? And things get even more confusing when we use the actual
publishKotlinMultiplatformPublicationToGitLabRepository
triggered by our CD/CI: we get two
daflkt-0.2.0.jar
files in the package registry (the ones I described above: one with 647 bytes with no classes and the correct one with 20kb). When testing
implementation("org.islandoftex:daflkt:0.2.0")
, the empty one is fetched. We are a bit puzzled on what to do. We are surely doing something wrong, but we cannot find what's happening. Any suggestion is welcome! (our
build.gradle.kts
is available in the linked repo). Thanks in advance!
✔️ 1
l
If I remember correctly, the 'KotlinMultiplatformPublication' just publishes the redirection. You should run 'publish' if you want to publish the full thing.
The JVM artifact gets named 'foo-jvm', and 'foo' redirects for each platform (so you don't have to specify the platform). That's why the smaller one seems 'empty'.
p
Thanks for the pointer! It seems that
publish
is an alias for the
KotlinMultiplatformPublication
task:
Copy code
➜ ./gradlew clean publish
> Task :publishKotlinMultiplatformPublicationToGitLabRepository FAILED
...
(running locally) Also, thanks for mentioning the redirection! Unfortunately,
foo-jvm
is not generated with the actual name (I understood the 20kb file should actually be
daflkt-0.2.0-jvm.jar
), so we cannot fetch it from
implementation("...")
. We are still a bit puzzled. 😅
o
TLTR: I think you should try using
publish
task (or
publishToGitLabRepository
- should not matter) in your CI/CD and everything should be fine after that > It seems
publish
is an alias for
KotlinMultiplatformPublication
It is not like that.
publish
task is an “aggregator” for all publications you have in your project. This includes
kotlinMultiplatform
and publications for all targets. And all those publications should be published together. Otherwise, the dependencies resolution in gradle won’t work when you use the library as a dependency. Also, as I can see there is no
daflkt-jvm
artifact published in the registry for version 0.2.0. Probably, this is the reason why you cannot fetch the artifact (and, most likely, it was not published because you used only a task to publish multiplatform artifact)
One more thing, I would suggest using
publishToMavenLocal
task when you checking how the publication works locally (but you probably will have to disable artifact signing). It is an equivalent for
publish
task but all artifacts will be published to your local maven repo
Copy code
>Task :publishJvmPublicationToGitLabRepository
Multiple publications with coordinates 'org.islandoftex:daflkt:0.2.0' are published to repository 'GitLab'. The publications 'jvm' in root project 'daflkt' and 'kotlinMultiplatform' in root project 'daflkt' will overwrite each other!
This is actually the reason why you don’t have jvm artifact published
You should not do that for each publication
it.artifactId = "daflkt"
The artifact ID will be automatically generated by kotlin plugin based on the project name and the target. So, you can simply remove this part. Also, I would suggest moving version manipulation from publications block to the
version
property. Like this:
Copy code
version = project.spotlessChangelog.versionNext.toString() +
                if (project.status.toString() == "development") "-SNAPSHOT" else ""
In this case you can completely remove group, artifactId and version changes in publications block. And you can use
publications.withType<MavenPublication> {}
method to configure publications instead the one you use right now
p
Oh my, thanks so much for the insightful explanation, @Oleg Smirnov! Great detective work on my
build.gradle.kts
file! 🕵️‍♂️ I will proceed as you suggested. Also, sorry to @Landry Norris for misunderstanding
publish
. 😅 I will check the docs too. Cheerio!
@Oleg Smirnov @Landry Norris Thank you very much, friends! I updated our project according to your suggestions/recommendations and now everything works like a charm! You rock! 🚀
🎉 1