Hi, I'm trying to add a `common` module as a depen...
# multiplatform
a
Hi, I'm trying to add a
common
module as a dependency to another
common
module but I'm not able to get it working. I tried with
implementation
,
api
and
compileOnly
but any of them give me a successful
build
. Could anyone helps me?
k
so you just have 2 separate source sets in the same build.gradle?
g
Multi-level common code is currently under heavy development https://youtrack.jetbrains.com/issue/KT-27801
a
I have 2 modules on the same project each of them with its own
build.gradle
h
Then just adding an
api
or
implementation
dependency on another project to the
commonMain
source set should work: you will be able to use the declarations from the other project's
commonMain
, and also platform-specific declarations in the appropriate platform-specific sources of the depending project.
Copy code
kotlin {
    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(project(":foo"))
            }
        }
    }
}
If it doesn't work for you, could you please provide more details about the project structure?
a
it doesn't, wait a sec I'll share the project
h
Also, as Alex Gherschon noted above, we are working to improve the behavior of such dependencies with custom source set hierarchies, which are now not fully supported yet, but the simple case with just
commonMain
and platform-specific sources should work.
a
When I try to build the project the
commonMain
is not able to find the
helloInit
value declarated inside the
separatedCommon
module
h
First, the
kotlin-platform-common
plugin is a part of Kotlin 1.2.x MPP tooling that is now becoming obsolete (no active development, and we have plans to deprecate it). Also, the current architecture of multiplatform projects requires that all expect declarations are provided with actual implementations within the same module, and no actual implementations can be added by a library consumer.
So, in your example,
separateCommon
should use the
kotlin-multiplatform
plugin, too, and should therefore provide platform-specific implementations for all its
expect
declarations.
a
Sorry I fixed the sample for a more clear sample of my issue
When I just have a
val
only needed on the
commonMain
sourceSet
oh, use the multiplatform plugin worked. Thank you so much