https://kotlinlang.org logo
Title
m

Marc Reichelt

02/22/2022, 12:17 PM
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:
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

ephemient

02/22/2022, 12:30 PM
what makes you think this will bundle the projects?
in any case, the usual advice is to publish everything
m

Marc Reichelt

02/22/2022, 12:34 PM
because that’s the same way how we can add projects to other projects in a jvm world?
e

ephemient

02/22/2022, 12:34 PM
in the JVM world it works the same way
m

Marc Reichelt

02/22/2022, 12:35 PM
so how do you split code across several modules then?
e

ephemient

02/22/2022, 12:35 PM
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

Marc Reichelt

02/22/2022, 12:36 PM
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

ephemient

02/22/2022, 12:42 PM
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

Marc Reichelt

02/22/2022, 12:45 PM
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

ephemient

02/22/2022, 12:56 PM
publishing to a maven repository, using Gradle's built-in mechanisms, which will align all the artifacts and their metadata
👀 1
e

ephemient

02/22/2022, 12:59 PM
I don't think they are, since they're talking about the JAR, which is not the same as bundling the native dependencies
a

ade

02/22/2022, 1:02 PM
For JARs I would also recommend publishing "normally" (separately). For the swift package, something like the above is required
m

Marc Reichelt

02/22/2022, 1:09 PM
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

ephemient

02/22/2022, 1:12 PM
just add the repository to
repositories { ... }
and include it like any other binary dependency
m

Marc Reichelt

02/22/2022, 1:12 PM
Hmm. I’ll try to get that working now. Let’s see where that takes me
a

ade

02/22/2022, 1:13 PM
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

ephemient

02/22/2022, 1:13 PM
you can use
mavenLocal()
for local testing
👍 1
a

ade

02/22/2022, 1:13 PM
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

Marc Reichelt

02/22/2022, 1:14 PM
@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

ade

02/22/2022, 1:15 PM
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

Marc Reichelt

02/22/2022, 1:16 PM
Yes, that’s exactly what I’m trying to achieve!
e

ephemient

02/22/2022, 1:16 PM
👍 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

ade

02/22/2022, 1:19 PM
the kmm submodules can also be published as kmm libraries as long as they are built for each platform, of course
m

Marc Reichelt

02/22/2022, 1:42 PM
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

ade

02/22/2022, 5:40 PM
In my project I am using a plugin to create a SPM package. https://github.com/ge-org/multiplatform-swiftpackage
m

Marc Reichelt

02/22/2022, 6:10 PM
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.