https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
m

Mikołaj Kąkol

08/25/2020, 9:21 AM
Hi, I was wondering if anyone tried to publish, a MPP lib that is build on multiple machines. Use case is: • build osx lib on mac • build Android on Unix • maybe building something on Windows How do I combine artifacts from each machine to a single artifatory? Since there is this
*.module
file in main lib, that contains information about every platform and calling multiple time
mavenPublish
or sth similar would override that
*.module
file. So basically it comes to how to publish artifacts build on different platforms to a single lib?
b

Big Chungus

08/25/2020, 9:27 AM
In your gradle script check your os and disable publishing for invalid platforms
Then you can safely fun publish on each platforms supported host. Let me find you a sample repo
There you go. They've made it even easier now https://kotlinlang.org/docs/reference/mpp-publish-lib.html
Trick is to upload your artifacts from multiple build and then mark them as published on your repo in last build
m

Mikołaj Kąkol

08/25/2020, 9:35 AM
so it will append extra variants only on artifactory? I won't remove anything. I have sample that: • first upload lib artifacts on mac, • and then on linux • compiles linux app using artifacts And it works, but if I swap first step with second it doesn't.
b

Big Chungus

08/25/2020, 9:36 AM
This will ensure that variats that can be built on multiple hosts will only be built on main host, thus allowing you to build everything in parallel
Just add systemProp mainHost to your main host job
m

Mikołaj Kąkol

08/25/2020, 9:40 AM
I'm not sure if I get it, I'll test and get back to you with it's okay
b

Big Chungus

08/25/2020, 9:50 AM
Sure
m

Marc Knaup

08/25/2020, 10:17 AM
How would you ensure that marking the uploads as published (e.g. with Bintray) happens last? usually the CI tasks run in parallel.
b

Big Chungus

08/25/2020, 10:18 AM
you can have stages in most CIs. So something like this:
Copy code
stageBuild:
 jobWin:
 jobMac:
 jobLin:
stagePublish:
 jobPublish:
m

Marc Knaup

08/25/2020, 10:20 AM
Would be great if anyone in the channel could provide a working example for GitHub Actions 🙂 So far I’m publishing everything manually from my MacBook which doesn’t scale too well and doesn’t support Linux/MingW 🙈
m

Mikołaj Kąkol

08/25/2020, 10:22 AM
that's what I'm trying, I'm using jenkins currently for something like that, however right now I'm not publishing anything 😕
Copy code
kotlin {
    android {
        if (OSKind.current != OSKind.OSX) {
            publishLibraryVariants("release", "debug")
        }
    }
    iosX64("ios") {
        binaries {
            framework {
                baseName = "K14Lib"
            }
        }
    }
    sourceSets {
        val commonMain by getting
        val commonTest by getting 
        val androidMain by getting 
        val androidTest by getting
        val iosMain by getting
        val iosTest by getting
    }

    configure(listOf(targets["metadata"], android(), iosX64("ios"))) {
        mavenPublication {
            val targetPublication = this@mavenPublication
            println("@@@@@@@@@@@@@@@@@@@@@@@ ${targetPublication.artifactId}")
            tasks.withType<AbstractPublishToMaven>()
                .matching { it.publication == targetPublication }
                .all { onlyIf { OSKind.current != OSKind.OSX } }
        }
    }
}

artifactory {
    setContextUrl("****")
    publish(delegateClosureOf<org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig> {
        repository(delegateClosureOf<org.jfrog.gradle.plugin.artifactory.dsl.DoubleDelegateWrapper> {
            setProperty("repoKey", "libs-release-local")
            setProperty("username", "publisher")
            setProperty("password", "****")
            setProperty("maven", true)
        })
        defaults(delegateClosureOf<groovy.lang.GroovyObject> {
            invokeMethod("publications", arrayOf(
                "androidDebug", "androidRelease", "ios", "iosArm64", "kotlinMultiplatform", "metadata"
            ))
        })
    })
}
I'm not sure if it's artifactory wrongly configured or maven part
m

Marc Knaup

08/25/2020, 10:25 AM
Do you need an Artifactory plugin and can’t just use the plain maven plugin? That’s my configuration:, but for Bintray https://github.com/fluidsonic/fluid-gradle/blob/7c138968d24165cbf17c010d8e0fac84cc52fc09/sources/LibraryModuleConfigurator.kt#L562 I find maven publishing very fragile in general 😕
m

Mikołaj Kąkol

08/25/2020, 10:27 AM
a

aleksey.tomin

08/25/2020, 10:37 AM
In github-actions you cat build and publish artifacts from different OS to the same tag
m

Marc Knaup

08/25/2020, 10:39 AM
What do you mean by “to the same tag”? Th question is how I can make the publication “public” after the last artifact has been uploaded, e.g. the “publish” action on Bintray.
a

aleksey.tomin

08/25/2020, 10:51 AM
> What do you mean by “to the same tag”? https://github.com/svenstaro/upload-release-action
tag: ${{ github.ref }}
I publish 4 artifacts - macos release/debug and windows release/debug
m

Marc Knaup

08/25/2020, 10:52 AM
Ah, we’re talking about maven publishing which I think works very differently 😅
a

aleksey.tomin

08/25/2020, 10:53 AM
Sorry 😞
m

Mikołaj Kąkol

08/25/2020, 1:08 PM
@Big Chungus it looks that it works, but I'm not sure why and if it's okay. What I have is lib build config like that (I removed artifactory plugin thx @Marc Knaup):
Copy code
val isPublishRun: String? by project

kotlin {
    android {
        if (OSKind.current != OSKind.OSX) {
            publishLibraryVariants("release", "debug")
        }
    }
    iosX64("ios") {
        binaries {
            framework {
                baseName = "K14Lib"
            }
        }
    }
    sourceSets {
        val commonMain by getting
        val commonTest by getting
        val androidMain by getting
        val androidTest by getting
        val iosMain by getting
        val iosTest by getting
    }

    configure(listOf(targets["metadata"], android(), iosX64("ios"))) {
        mavenPublication {
            val targetPublication = this@mavenPublication
            val shouldPublish = isPublishRun == "yes"
            tasks.withType<AbstractPublishToMaven>()
                .matching { it.publication == targetPublication }
                .all { onlyIf { shouldPublish } }
        }
    }
}
Then I run jobLin/Mac in parallel and then jobPublish with this
shouldPublish
set to true. After that I can compile iOS and Android App just fine. But I don't know if artfiacts on artifactory should look like this: https://artifactory.speednet.pl/artifactory/public/me/mikolaj/K14-test-mobileLib/1.4-SNAPSHOT/ (user: public, pass: publicpublic) it looks like that this
module
thing was 3 uploaded times
m

Marc Knaup

08/25/2020, 1:10 PM
Looks like all the subdirectories are missing 😮 That’s how it should look like: https://repo1.maven.org/maven2/io/fluidsonic/locale/
m

Mikołaj Kąkol

08/25/2020, 1:11 PM
m

Marc Knaup

08/25/2020, 1:12 PM
I’ve never done it with SNAPSHOT builds - it could lead to different results so it may be fine. But for iOS there should be two artifacts. You also need
iosArm64
for the device.
iosX64
only works for the simulator.
m

Mikołaj Kąkol

08/25/2020, 1:13 PM
yes, it just proof of concept for this building from multiple machines
m

Marc Knaup

08/25/2020, 1:14 PM
Ah okay 🙂
Difficult to tell if it’ll be correct without actually using it. So many things that could go wrong.
5 Views