Another question: in our project, we want to have ...
# multiplatform
m
Another question: in our project, we want to have multiple KMM / Gradle modules, which then get bundled by one root Gradle project (which will build the JAR / Swift Package). So far, this is what I try to use:
Copy code
kotlin {
    jvm()
    ios()
    
    sourceSets {
        commonMain {
            dependencies {
                api(project(":ModuleOne"))
                api(project(":ModuleTwo"))
            }
        }
    }
    
    // ...
}
But: the generated lib only has 261 bytes, it only contains the
META-INF/MANIFEST.MF
and that’s it. No classes compiled. What should I be doing instead?
Interestingly this is documented on https://kotlinlang.org/docs/multiplatform-mobile-add-dependencies.html#dependency-on-another-multiplatform-project - but it doesn’t seem to work on my machine
e
what makes you think this will bundle the projects?
in any case, the usual advice is to publish everything
m
because that’s the same way how we can add projects to other projects in a jvm world?
e
in the JVM world it works the same way
m
so how do you split code across several modules then?
e
publishing a project with
dependencies { api(project(":Module")) }
does not bundle it, it sets up the artifact's metadata to include the dependency by name+version
publish the module and the modules it depends on
m
Ah, I see. So what I would need to do is generate a fat jar, which bundles all the referenced jars…
We currently have two Git repos (Android / iOS), with the new multiplatform git repo seperately. That Git repo currently is a single Gradle project (building a JAR/ Swift package that can be included in the app projects). Now we want to split up that multiplatform project into multiple feature projects to make it easier for multiple teams to work on them. Does anyone try something similar, and has a good reference for that?
e
publishing a fat jar is already problematic in pure JVM; it's even worse with KMP as it relies on Gradle metadata. I would advise you to publish normally.
m
What does ‘publish normally’ mean to you?
Thank you for helping by the way!
I hope this can be solved in a good way, because otherwise we’ll be having a hard time using KMM in our project.
e
publishing to a maven repository, using Gradle's built-in mechanisms, which will align all the artifacts and their metadata
👀 1
e
I don't think they are, since they're talking about the JAR, which is not the same as bundling the native dependencies
a
For JARs I would also recommend publishing "normally" (separately). For the swift package, something like the above is required
m
Hmm, that would actually be the best world: publishing all JARs as single JARs, and combining them altogether as a single XCFramework for iOS.
I just wanted to publish a fat JAR as an intermediate step (on our way to publish every single JAR artifact), but if it’s actually easier to publish every single jar I think we should do that 👍
@ade @ephemient do you have a good guide how to include all those JARs in the app project later on?
e
just add the repository to
repositories { ... }
and include it like any other binary dependency
m
Hmm. I’ll try to get that working now. Let’s see where that takes me
a
I think it depends if you want to just use it in the KMM module code or actually publish all classes to iOS aswell so that they are available
e
you can use
mavenLocal()
for local testing
👍 1
a
or rather, in my experience, you cant link a pure kotlin module into a kmm module, so the dependenices must be kmm modules with all the same targets specified
m
@ade I basically want to bundle
FeatureA
,
FeatureB
,
FeatureC
into a single
Multiplatform.xcframework
but for the Android world, individual
FeatureA.jar
and
FeatureB.jar
and
FeatureC.jar
are actually good 👍
a
Ok, I think you need to create a swift package from a "umbrella module" that depends on the other KMM modules
that's how I understand it, also based on https://youtrack.jetbrains.com/issue/KT-30088
m
Yes, that’s exactly what I’m trying to achieve!
e
👍 bundling native dependencies into a single framework makes sense since cocoapods isn't able to follow the GMM/KMP metadata itself, and it's also a bit similar on the JS/Node publishing side where you do need to bundle dependencies that aren't in NPM in order to make them available to library consumers, but for JVM, it's definitely most natural to just use the existing Maven support
a
the kmm submodules can also be published as kmm libraries as long as they are built for each platform, of course
m
I’ll try to do that now and report back 🙂
So I tried to combine the new
XCFramework
with the blog post you mentioned @ade - but unfortunately it doesn’t compile anything for me - it doesn’t even create a single framework 😕
is there an updated guide for Kotlin 1.6.10 with the
XCFramework
task?
a
In my project I am using a plugin to create a SPM package. https://github.com/ge-org/multiplatform-swiftpackage
m
yeah, we used that plugin before - but we stopped using it when we found out that now there is an official
XCFramework
task that creates the framework, and we started creating the swift package ourselves (because in the end it’s just a plain
Package.swift
file with the framework, zipped together). Still, using that plugin as well as using
XCFramework
: we need to find out how to integrate the different feature modules
FeatureA
,
FeatureB
etc.