G'day folks, I've found some somewhat unexpected ...
# multiplatform
t
G'day folks, I've found some somewhat unexpected behaviour for non-maven outputs of KMP libraries that depend on other KMP libraries. I'm currently unsure if it's a problem I've caused somehow, or whether the current state of KMP doesn't really handle this. Seeking advice. We have a KMP monorepo, with multiple Gradle modules each being their own KMP library. Each of these KMP libraries produces outputs for JVM, Android, Cocoapods, and JavaScript. I recently added a new KMP library in the monorepo called
fundamental
. I then updated an existing KMP library
foo
in the monorepo to depend on
fundamental
. Part of the API of
foo
now contains a reference to type
Bar
that is defined in
fundamental
. I achieved this via adding a Gradle inter-project
api
dependency in `foo`'s `build.gradle.kts`:
Copy code
commonMain.dependencies {
            ...
            api(project(":fundamental"))
        }
For Maven outputs of the KMP process, the
foo
library correctly depends on the
fundamental
library, as is shown in the generated POM file for `foo`:
Copy code
...
  <groupId>com.example</groupId>
  <artifactId>foo</artifactId>
...
    <dependency>
      <groupId>com.example</groupId>
      <artifactId>fundamental</artifactId>
      <version>1.0.0</version>
      <scope>runtime</scope>
    </dependency>
...
For the Cocoapods output,
foo
does not depend on
fundamental
. The only dependencies in the podspec file are the third-party dependencies specified in the
kotlin { cocoapods { ... } }
DSL of
build.gradle.kts
.
Copy code
Pod::Spec.new do |spec|
...
    spec.dependency 'SomeThirdPartyLibrary', '1.44.0'             
end
Instead of having an inter-library dependency, KMP has instead copied the class from
fundamental
into
foo
and has renamed it to have a
Fundamental
prefix. In the cocoapod for
foo
, the type of the
Bar
object in the API is
AKFMFundamentalBar
. In the cocoapod for
fundamental
, the type of the
Bar
object in the API is
AKFBar
. This is a bit concerning as
foo.FundamentalBar
is not the same type as
fundamental.AKFBar
and cannot be assigned to one another. A similar thing is happening in the JS output.
foo
does not depend on
fundamental
. The only dependencies in the
package.json
file are explicitly defined third-party dependencies and `format-util`:
Copy code
"dependencies": {
        "some-third-party-library": "1.4.0",
        "format-util": "^1.0.5"
    }
KMP has duplicated the type definition for
Bar
in both the
fundamental
and
foo
JavaScript libraries (no renaming unlike Cocoapods). Note that even though the types are duplicated between the two libraries, you can actually assign from one to the other as they are structurally equivalent and that's all TypeScript cares about. I'm looking for advice as to what's going on here. Have I done something dumb? Is inter-project monorepo KMP libraries with dependency management not possible to achieve with Cocoapods and JavaScript outputs currently? Something else?