I’m a little bit confused with the `dependsOn` rel...
# multiplatform
z
I’m a little bit confused with the
dependsOn
relation for the source sets. Let’s say I have structure like this:
Copy code
sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("org.jetbrains.kotlin:kotlin-stdlib")
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version")
        }

        val androidMain by getting {
            dependsOn(commonMain)

            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version")
                implementation("com.android.support:support-compat:28.0.0")
            }
        }
In such scenario,
androidMain
will get from the
commonMain
everything, including the
coroutines-core-common
? (But I don’t think I need this as in
androidMain
I have
coroutines-core
) Isn’t it better to declare exact dependencies for every source set than use
dependsOn
?
k
That is a good question
I think modules dependsOn(commonMain) already happen automatically
In this talk they explain a bit more on how dependsOn work:

https://www.youtube.com/watch?v=oBv1QykLAXc

👀 1
11:20
k
dependsOn
is useful for say, common code between 2 iOS targets, or common code between iOS and macOS tagrgets
obviously your target specific source sets automatically depend on your common source sets
dependencies block is for external dependencies. dependsOn is for internal sources
z
@Kris Wong Seems like a lot of magic is happening under the hood there lol What exactly do you mean by internal sources?
k
sources within your module
k
🤔 like Kotlin multimodules?
Something similar than
Copy code
implementation project(':businesslogic')
?
z
@Kris Wong
Copy code
obviously your target specific source sets automatically depend on your common source sets
Does it work for Android tests too? I have
commonTests
that looks like this
Copy code
kotlin {
    val uniqueName = "${project.rootProject.name}${project.name.capitalize()}"

    android()
    ios {
        binaries {
            framework(uniqueName)
        }
    }

    sourceSets {

        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
                implementation(Koin.test)
            }
        }
    }
}
And still above the
kotlin
block I have to put:
Copy code
dependencies {
    testImplementation(kotlin("test", Build.Versions.kotlin))
    testImplementation(kotlin("test-junit", Build.Versions.kotlin))
    testImplementation(Koin.test)
}
k
yes, it works for tests