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

Riccardo Montagnin

03/05/2019, 9:14 AM
Hello everyone, how do I include all the
androidMain
dependencies into
androidTest
? Should I just copy/paste them or is there a better method to do it, like a reference?
l

louiscad

03/05/2019, 9:20 AM
Aren't they already available? I think
androidTest
depends on
androidMain
, is that the case?
r

Riccardo Montagnin

03/05/2019, 9:25 AM
It doesn't look like that, it seems they are indipendent
g

gildor

03/05/2019, 9:25 AM
Looks like some issue (not sure on which level, build.gradle, MPP plugin or Android Gradle)
This is how it should work out of the box, if it doesn’t would be good to reproduce it and report an issue to Kotlin issue tracker, most probably it’s some MPP plugin problem
n

nestserau

03/05/2019, 9:31 AM
I don’t know whether it’s a bug or a feature, but a solution to your question would be a
configure
block.
g

gildor

03/05/2019, 9:32 AM
it’s not a feature
n

nestserau

03/05/2019, 9:32 AM
Copy code
sourceSets {
        all {
            languageSettings {
                languageVersion = '1.3'
                useExperimentalAnnotation 'kotlin.ExperimentalUnsignedTypes'
            }
        }
        commonMain {
            dependencies {
                implementation kotlin('stdlib-common')
                implementation "io.ktor:ktor-client-core:$ktor_version"
            }
        }
        commonTest {
            dependencies {
                implementation kotlin('test-common')
                implementation kotlin('test-annotations-common')
            }
        }
        iosX64Main {
            kotlin.srcDirs += 'src/iosMain'
        }
        iosX64Test {
            kotlin.srcDirs += 'src/iosTest'
        }
        iosArm64Main {
            kotlin.srcDirs += 'src/iosMain'
        }
        iosArm64Test {
            kotlin.srcDirs += 'src/iosTest'
        }
        configure([iosX64Main, iosArm64Main]) {
            dependencies {
                implementation "io.ktor:ktor-client-ios:$ktor_version"
            }
        }
        androidMain {
            dependencies {
                implementation kotlin('stdlib-jdk8')
            }
        }
        androidTest {
            dependencies {
                implementation 'junit:junit:4.12'
                implementation 'org.jetbrains.kotlin:kotlin-test'
                implementation 'org.jetbrains.kotlin:kotlin-test-junit'
            }
        }
        configure([androidMain, androidTest]) {
            dependencies {
                implementation "io.ktor:ktor-client-android:$ktor_version"
            }
        }
    }
@Riccardo Montagnin Take a look at how I’m using the
configure
block here, hope that helps.
g

gildor

03/05/2019, 9:34 AM
This is a workaround, but it shouldn’t work like that
r

Riccardo Montagnin

03/05/2019, 9:36 AM
@nestserau Yeah that worked
@gildor Where should I report it?
g

gildor

03/05/2019, 9:36 AM
Kotlin issue tracker
l

louiscad

03/05/2019, 10:11 AM
d

Dominaezzz

03/05/2019, 11:22 AM
I'm not sure about it being a bug and all, but I think you might want to consider using
api
instead of
implementation
.
I don't think you should be depending on the "internal" dependencies of your dependencies.
g

gildor

03/05/2019, 11:42 AM
But this is how main/test dependencies work
Test source set have special relationship with main, for example you have access to internal members and dependencies, this is how it works by default for Java and Kotlin projects and for Android projects without MPP
d

Dominaezzz

03/05/2019, 11:59 AM
Ah I forgot about that.
r

Riccardo Montagnin

03/05/2019, 2:10 PM
Also I've reported an
internal
bug that I've encountered: https://youtrack.jetbrains.com/issue/KT-30273
r

russhwolf

03/05/2019, 2:39 PM
The first bug is already reported at https://youtrack.jetbrains.com/issue/KT-29343
r

Riccardo Montagnin

03/05/2019, 3:08 PM
Thanks, commented mine telling it's a duplicate