Hi Folks, I’m facing an issue with my KMP dependen...
# multiplatform
v
Hi Folks, I’m facing an issue with my KMP dependencies on my Android/JVM project while i’m testing, there is my trouble:
Copy code
androidTest {
    dependsOn(commonTest)
    dependencies {
        implementation("io.mockk:mockk:$mockkVersion") // <-- this dependency is also added to the `androidAndroidTest` source set
    }
}
androidAndroidTest {
    dependsOn(commonTest)
    dependencies {
        implementation("io.mockk:mockk-android:$mockkVersion")
    }
}
For an unknown reason, my dep
io.mockk:mockk
is also added to the
androidAndroidTest
source set.
🧵 2
1
When I run the task
:shared:dependencies
and I look at
debugAndroidTestRuntimeClasspath
I get:
Copy code
+--- io.mockk:mockk-android:1.12.2
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.72 -> 1.6.10
|    |    \--- org.jetbrains:annotations:13.0
|    +--- io.mockk:mockk:1.12.2
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.72 -> 1.6.10 (*)
|    |    +--- io.mockk:mockk-agent-jvm:1.12.2
|    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.72 -> 1.6.10 (*)
|    |    |    +--- org.jetbrains.kotlin:kotlin-reflect:1.3.72
|    |    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.72 -> 1.6.10 (*)
|    |    |    +--- io.mockk:mockk-agent-api:1.12.2
|    |    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.72 -> 1.6.10 (*)
|    |    |    +--- io.mockk:mockk-agent-common:1.12.2
|    |    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.72 -> 1.6.10 (*)
|    |    |    |    \--- io.mockk:mockk-agent-api:1.12.2 (*)
|    |    |    +--- org.objenesis:objenesis:3.1
|    |    |    +--- net.bytebuddy:byte-buddy:1.12.5
|    |    |    \--- net.bytebuddy:byte-buddy-agent:1.12.5
|    |    +--- org.jetbrains.kotlin:kotlin-reflect:1.3.72 (*)
|    |    +--- io.mockk:mockk-common:1.12.2
|    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.72 -> 1.6.10 (*)
|    |    |    \--- io.mockk:mockk-dsl:1.12.2
|    |    |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.72 -> 1.6.10 (*)
|    |    \--- io.mockk:mockk-dsl-jvm:1.12.2
|    |         +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.72 -> 1.6.10 (*)
|    |         +--- org.jetbrains.kotlin:kotlin-reflect:1.3.72 (*)
|    |         \--- io.mockk:mockk-dsl:1.12.2 (*)
|    +--- io.mockk:mockk-agent-android:1.12.2
|    |    +--- io.mockk:mockk-agent-api:1.12.2 (*)
|    |    +--- io.mockk:mockk-agent-common:1.12.2 (*)
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.72 -> 1.6.10 (*)
|    |    +--- com.linkedin.dexmaker:dexmaker:2.28.1
|    |    |    \--- com.jakewharton.android.repackaged:dalvik-dx:9.0.0_r3
|    |    +--- org.objenesis:objenesis:2.6 -> 3.1
|    |    \--- org.jetbrains.kotlin:kotlin-reflect:1.3.72 (*)
|    \--- io.mockk:mockk-agent-api:1.12.2 (*)
If I run exactly the same task without
implementation("io.mockk:mockk:$mockkVersion")
I get:
Copy code
+--- io.mockk:mockk-android:1.12.2
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.72 -> 1.6.10
|    |    \--- org.jetbrains:annotations:13.0
|    +--- io.mockk:mockk:1.12.2
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.72 -> 1.6.10 (*)
|    |    +--- org.jetbrains.kotlin:kotlin-reflect:1.3.72
|    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.72 -> 1.6.10 (*)
|    |    +--- io.mockk:mockk-common:1.12.2
|    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.72 -> 1.6.10 (*)
|    |    |    \--- io.mockk:mockk-dsl:1.12.2
|    |    |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.72 -> 1.6.10 (*)
|    |    \--- io.mockk:mockk-dsl-jvm:1.12.2
|    |         +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.72 -> 1.6.10 (*)
|    |         +--- org.jetbrains.kotlin:kotlin-reflect:1.3.72 (*)
|    |         \--- io.mockk:mockk-dsl:1.12.2 (*)
|    +--- io.mockk:mockk-agent-android:1.12.2
|    |    +--- io.mockk:mockk-agent-api:1.12.2
|    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.72 -> 1.6.10 (*)
|    |    +--- io.mockk:mockk-agent-common:1.12.2
|    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.72 -> 1.6.10 (*)
|    |    |    \--- io.mockk:mockk-agent-api:1.12.2 (*)
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.72 -> 1.6.10 (*)
|    |    +--- com.linkedin.dexmaker:dexmaker:2.28.1
|    |    |    \--- com.jakewharton.android.repackaged:dalvik-dx:9.0.0_r3
|    |    +--- org.objenesis:objenesis:2.6
|    |    \--- org.jetbrains.kotlin:kotlin-reflect:1.3.72 (*)
|    \--- io.mockk:mockk-agent-api:1.12.2 (*)
As you can see,
io.mockk:mockk-agent-jvm
is added in the first case but not in the second case.
I don’t understand why this append, I don’t declare any dependency between
androidAndroidTest
and
androidTest
so
androidTest
’s deps shouldn’t affect ``androidAndroidTest` ’s deps... (Probably related to https://kotlinlang.slack.com/archives/C3PQML5NU/p1597873415394100)
I’ve discovered that some generated gradle configurations dedicated to
androidAndroidTest
inherit from a configuration named
androidTestImplementation
. I think this conf should’t be associated to the
androidAndroidTest
confs because this conf is already used by the
androidTest
source set.
So, to fix my issue, I exclude the conf
androidTestImplementation
from the configurations dedicated to 
androidAndroidTest
. There is my code:
Copy code
afterEvaluate {
    configurations.findAll { it.name.contains("AndroidTestRuntimeClasspath") || it.name.contains("AndroidTestCompileClasspath") }.forEach {
        it.setExtendsFrom(it.extendsFrom.findAll { it.name != "androidTestImplementation" })
    }
}