https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
a

AdrianRaFo

05/24/2019, 1:50 PM
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

Kris Wong

05/24/2019, 2:06 PM
so you just have 2 separate source sets in the same build.gradle?
g

galex

05/24/2019, 2:16 PM
Multi-level common code is currently under heavy development https://youtrack.jetbrains.com/issue/KT-27801
a

AdrianRaFo

05/24/2019, 2:17 PM
I have 2 modules on the same project each of them with its own
build.gradle
h

h0tk3y

05/24/2019, 2:36 PM
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

AdrianRaFo

05/24/2019, 2:37 PM
it doesn't, wait a sec I'll share the project
h

h0tk3y

05/24/2019, 2:39 PM
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

AdrianRaFo

05/24/2019, 3:43 PM
When I try to build the project the
commonMain
is not able to find the
helloInit
value declarated inside the
separatedCommon
module
h

h0tk3y

05/24/2019, 3:58 PM
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

AdrianRaFo

05/24/2019, 4:02 PM
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
2 Views