Hi peeps! :wave: I've just published a <new articl...
# feed
v
Hi peeps! 👋 I've just published a new article about publishing a Kotlin Multiplatform library on Maven Central, with Github Actions. If you come from the Java/Android world, you might know about JitPack and it's simplicity to easily publish your libraries. But unfortunately, it is not yet compatible with Kotlin Multiplatform libraries. Let me know what you think, I'd appreciate your feedback 🙂
👍 2
r
I think you should specify clearly, there are currently two totally different methods of publishing libs to maven central (different accounts, different gradle plugins) and only the new method (Publishing Portal) is available for new namespaces. There was a very long discussion not long ago: https://kotlinlang.slack.com/archives/C3PQML5NU/p1707673013826779
1
j
Nice. I gave up trying to publish stuff there with my multiplatform & multi module project. Just agonizingly painful to debug when it doesn't work. Why is this stuff so extremely tedious and painful in 2024? Publishing stuff is vastly easier in almost any other language/package manager. Anyway, here's a couple of workarounds that works with zero plugins for any gradle project: If you have access to AWS or GCP, it's really easy to publish to a file bucket with gradle. You don't need any plugins for this even. This works out of the box. We have a public maven repository backed by a gcp bucket and Google CDN. Zero hassle. Works great. Just gradle publish and make sure you have your environment set up with credentials. If you don't have AWS/GCP but do have a server that you can access with ssh. Gradle knows how to publish there too. Almost any hosting provider can get you this. If that's still not good enough, publish to your local filesystem and synchronize the files to some remote server that you can access with http/https. You do not need any maven repository software. It's just an extremely convoluted way to upload files to some server. Wrapped in layers of complexity and pointless ceremony.
r
In general new Publishing Portal API makes things a lot easier and nmcp gradle plugin by @mbonnin (https://github.com/GradleUp/nmcp) is now quite easy to use even for multi module and multiplatform kotlin projects.
🎉 3
v
Thank you @Robert Jaros for your feedback! I actually tried to create a 'groupId' on the legacy option, just to check if it was still possible, but they disabled it. So the only option now seems to be the new Publishing portal, if I'm not mistaken?
👌 1
Oh, I was not aware of this repo, thanks for sharing! I'll take a look. Happy to see some people already created easy solutions for the new Publishing portal! 🚀
@Jilles van Gurp I totally agree with you. I spent a few days trying to make it work, testing different options until I finally managed to make it work. It was painful but rewarding at the end! Your solution looks good with AWS or GCP! But having your own Maven repository on these platforms also requires some time and effort to set it up, I'm guessing? I'm a solopreneur, so time is a valuable resource as you can imagine 😁
s
) and only the new method (Publishing Portal) is available for new namespaces.
@Robert Jaros I have a namespace created around few years back and they migrated it to new publishing portal immediately after sending an email to
<mailto:central-support@sonatype.com|central-support@sonatype.com>
, which now works with nmcp plugin.
j
@Vivien Mahé file buckets are super easy. Just add the repository:
Copy code
configure<PublishingExtension> {
            repositories {
                maven {
                    // GOOGLE_APPLICATION_CREDENTIALS env var must be set for this to work
                    // public repository is at <https://maven.tryformation.com/releases>
                    url = uri("<gcs://mvn-public-tryformation/releases>")
                    name = "FormationPublic"
                }
            }
        }
And that's it. You need gcloud setup and some credentials that allow you to access your bucket. There's a github action as well that sets that up where you just add your credentials as a secret in your repo. We have both private and external repos. We also have our load balancer setup to serve files from our bucket via Google's CDN. This enables https for your users. But for a private, internal repository, you can just stick to buckets. Amazon has similar features except of course you would use s3. Both are supported out of the box with gradle if you have the sdks installed. SSH is even more simple. All you need is ssh access to some server and set up your public key and it will work. If the remote server has a webserver running, others can of course use https. Super easy to setup.
👍 1
v
@Jilles van Gurp Thank you for this detailed explanation! I'll look into it 🙂 You should write an article about your setup, pretty sure it'll help a lot of devs as well!
s
@Jilles van Gurp The issue is, it’s difficult to get approval for other repos/proxy in enterprise envs. Central is always safe option as it already approved in most corporate envs.
j
Never had that issue but I appreciate some environments are more locked down. Sadly, not in a mood to take a sabbatical to set up something that should just work. I've sunk enough time on the whole maven central thing and this just works with zero hassle.
c
I actually post my own KMP libs on the new repository, for example cachemap is hosted there. I remember it being particularly difficult because the kmp plugin creates file structure that is not compatible and I have to remove a bunch of files before uploading but it does work