Happy Sunday folks, Does someone know of a way to...
# multiplatform
a
Happy Sunday folks, Does someone know of a way to prevent
sources.jar
from being published in a kotlin multiplatform [androidJvm target] project? I have a requirement not to publish the source code with the artifacts on sonatype but I can not get the setup to skip publishing sources.jar. I would eventually like to replace the sources.jar with an empty-sources.jar (to satisfy maven central’s constraints), but I cant get to remove the sources.jar from being published to begin with. Here is what I tried: • I checked that I am not adding sources.jar artifact in publications closure. • I created a task that finalizes the sourcesjar task to delete the generated sources.jar, but gradle smartly recognizes that some files are deleted and it re-creates the sources.jar. • I also created a task that creates an empty-sources.jar which I then added to publications closure like so
artifact(emptySourcesJar.get())
but I get an error saying : Invalid publication ‘androidRelease’: multiple artifacts with the identical extension and classifier (‘jar’, ‘sources’). which is really nice error messaging since that tells me that I can not have multiple sources.jars, but I tried this thinking it could replace the one automatically being generated by the multiplatform plugin. • I tried searching the channel, stackoverflow for any similar discussions but couldnt find any (they were mostly looking to publish missing sources.jar) I am using multiplatform version 1.7.21 and followed the guilde here to publish to maven central. The guile is well written and works like a charm, just that I need not to publish sources.jar. It would be really cool if someone could point me in the right direction here. Thanks
👀 1
e
Maven Central requires a sources.jar
are you publishing to Maven Central specifically, or to some other Maven repository?
in any case, there is no option: the Kotlin multiplatform Gradle plugin always sets up the publication to include sources. you can hack around it with
Copy code
// needs to be fully-qualified in buildscripts because org.gradle.api.tasks.bundling.Jar is a default import
tasks.withType<org.gradle.jvm.tasks.Jar>()
    // sources JARs from all variants
    .matching { it.name.endsWith("sourcesJar", ignoreCase = true) }
    .configureEach {
        // use this if you want to prevent publication
        enabled = false
        // use this if you want to publish an empty JAR
        exclude("*")
    }
a
Maven. Yeah, but that sources.jar can be empty as well. I would like to find a way to not add code source to sources.jar. Or at least configure the setup so that sources.jar isn’t produced at all at least. Thanks so much for taking time to respond and sharing the code snippet, very much appreciated. I will try this snippet.
Update: Hey ephemient, thanks again for sharing the snippet. This did the trick.