I have a big JVM/Android/iOS multiplatform project...
# multiplatform
r
I have a big JVM/Android/iOS multiplatform project with dozens of libs as modules. Let’s say I have a backend developer who wants to make changes to some modules and try these changes locally in their project. Is there an easy way to publish all artifacts for one platform in a multi-modules project or do I need to create custom tasks? Anyone made such tasks? I myself am using
publishToMavenLocal
a lot while working (for example) only on iOS and only in the simulator, so I would benefit from this kind of feature
I suppose I would need to publish both the platform and the meta/sources thingies
a
Yes, you can do that. For example lets assume this example setup:
Copy code
plugins {
    kotlin("multiplatform")
    `maven-publish`
}

group = "test"
version = "1.0"

kotlin {
    jvm()
    linuxX64()
    mingwX64()
}
And locally you want to publish only
linuxX64
. You can do that by calling gradle task:
publishLinuxX64PublicationToMavenLocal
which will publish only linuxX64 target to your mavenLocal. But for MPP projects its often required to publish common library as well. In order to do that you need to call:
publishKotlinMultiplatformPublicationToMavenLocal
. It is also possible to define custom maven repositories, for example, to publish it to a certain file directory. To do so you need to declare maven repository like that:
Copy code
publishing {
    repositories {
        maven {
            name = "projectRoot"
            setUrl("${rootProject.rootDir}/repo")
        }
    }
}
Then Kotlin Gradle Plugin will create appropriate tasks for you to publish lib to that location.
publishKotlinMultiplatformPublicationToProjectRootRepository
publishLinuxX64PublicationToProjectRootRepository
You can spot the pattern of how the tasks are named. It is:
"publish" + targetName + "Publication" + "To" + repositoryName + "Repository"
r
Thanks! So I should be able to just use
./gradlew publishKotlinMultiplatformPublicationToMavenLocal publishJvmPublicationToMavenLocal
and then another one because I have pure JVM modules too (non KMP). That’s very long I’ll probably add some tasks that just depend on everything you have to call depending on the platform, but at least I don’t have to iterate over all modules
m
You could also use composite builds in Gradle.
r
Why?
m
I'm just providing an alternative option to
publishToMavenLocal
. If they are making regular changes in the dependency project and testing them locally, Gradle will handle re-compiling automatically with no need to run manual steps between changes.
r
Oh you mean have the libraries as a build dependency of the project using them. No that’s not possible, there are many modules/libraries in this project and many projects using them. People are generally not fluent in Gradle
m
I don't know the makeup of your team and the familiarity with Gradle. I was just suggesting an option that would help the development workflow if there was interest.
r
I feel like composite builds would make more sense for me with projects more strongly tied together, like an android project relying on a shared KMM module, this kind of stuff. I’m dealing with mostly PHP devs here, so having a command to run written in a readme seems easier than an explanation on how to configure gradle files and making sure projects are located correctly locally But thanks for the suggestion, I forgot that composite builds were a thing
m
Composite builds work well for testing how changes in a dependency affect a specific dependent. If it's something that happens frequently, then might be worth looking into. If it's a one time thing, or a few time thing, publishToLocal won't hurt anybody
e
composite builds are unfortunately not supported for Kotlin multiplatform: https://youtrack.jetbrains.com/issue/KT-52172
m
That's sad... Didn't realize that.
a
composite builds are unfortunately not supported for Kotlin multiplatform: https://youtrack.jetbrains.com/issue/KT-52172
They are partially supported. But we want to extend this support further and making it more stable. So you are very welcome to try and share your feedback. 🙂