Trying to publish a private library using KMP, I w...
# multiplatform
s
Trying to publish a private library using KMP, I was taking a look at this excellent post on publishing Android libraries to Maven Central and I was wondering. How far is an approach like this for a KMP project instead of an Android-only one? Is this setup still something that we can go for if our project is not open sourced? Prob not the right channel exactly for this question, but a bunch of you have probably gone through the process of publishing a MP library so you may be able to give me a hint or two.
j
Similar setup, but you don't need to setup the sources, KGP does that automatically
s
You mean this part of the post?
Copy code
task androidSourcesJar(type: Jar) {
    archiveClassifier.set('sources')
    if (project.plugins.findPlugin("com.android.library")) {
        // For Android libraries
        from android.sourceSets.main.java.srcDirs
        from android.sourceSets.main.kotlin.srcDirs
    } else {
        // For pure Kotlin libraries, in case you have them
        from sourceSets.main.java.srcDirs
        from sourceSets.main.kotlin.srcDirs
    }
}

artifacts {
    archives androidSourcesJar
}
And for the other part of my concerns, is there a lot more on top of this that one would have to do to publish this privately instead of an open source library? Total noob to doing this kind of stuff so I feel like I may be asking silly questions here 🙈
j
yes, that part
not sure about the private repo, I have only published public repositories
s
Yeah I’ve been trying to figure it out myself too, and it doesn’t seem like it unless I’m really missing smth. Gonna have to try and at least get the Android part work with Jitpack I guess unless I find an alternative or figure out if i’m wrong about this assumption 🤷‍♂️
j
Not sure if jitpack supports kmp
a
last time I checked, jitpack had issues with gradle metadata
b
This might give you some ideas for setup github.com/mpetuska/template-kmp-library I found that the hardest part is actually not the publishing itself, but building all the platform dependant artefacts and avoiding duplicates
s
No jitpack doesn't support KMP. I'm trying to take it one step at a time basically, first try and somehow figure out how to upload the private artifact somewhere other than Jitpack preferably and then I'll try and figure out how to do the KMP parts. Thanks for the link Martynas!
j
Why do you want to keep it private? they will be able to get the sources from the public repo 🤔
s
No sorry maybe I didn't explain it well. For this specific case, we're working on a private GitHub repository, which we need to not make open source. If it was public, I'd simply be able to follow the post I linked above, but this is outside of my hands, it is only to be consumed by ourselves.
m
I'm 99% sure you can publish to mavenCentral a closed source app as long as you're sending empty sources and javadoc jars
s
Hmm, but would I still be able to not allow others to download the library at all? We’re doing some POC and I can’t guarantee that the library itself will not be using some of our private tokens and such in the source code. So it would not be a good thing if someone can download it and use our library since we’re not exactly being careful with that stuff, at least not while we’re making this POC work for us.
m
Ah yea in that case, MavenCentral is not where you want to put your jar. Anyone can download them
s
Yeap, so that’s not it. I really wish we could just open source it instead and make my life easier 😅 I feel like I’m in first year university all over again, where I have an idea of what I want to do, but I have no clue how to properly google for it and recognize if what I am looking at is in fact what I am looking for. This was exactly the feeling when I remember first starting to learn Java 😅
j
@Stylianos Gakis why can you change the design of the library to accept those tokens externally? the public repo can get those tokens via secrets for your own purposes
For example, I worked on a library which uses Figma API tokens, for E2E tests I need to provide a token, but the library hasn't one hardcoded, it can be provided via constructor or environment variables (I am not sure about how it is the state of environment variables in KMP, but you could generate in
build
the token from a Gradle task too.
s
Hmm, well that library is more of an SDK if you can call it that, it's meant to be a drop-in work from scratch solution for our internal app. Where in the app we just add the dependency and call an entry point and it should just work. Changing that, just so we can host the repo publicly feels like fixing the wrong problem (we may even end up doing that if I got no more hair to pull after this). Like this must be something that others have gone through before, like this article explains too (hosting their own artifactory, in the section "Deploying Kotlin Multiplatform artifacts using GitHub Actions") I just need to figure out how to do that now and I feel really stupid not having figured out yet 😅
196 Views