Tim Dawborn
08/21/2024, 10:38 AMfundamental. 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`:
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`:
...
<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.
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`:
"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?