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

andymin

07/09/2020, 8:14 PM
Hello, I have a project setup as such in which jvm1 and jvm2 and different targets:
Copy code
src
* commonMain
* commonTest
* jvm1Main
* jvm2Main
* jvm2Test
I want it so that running
check
or
build
would run
jvm2Test
and
commonTest
so I setup my `build.gradle`:
Copy code
kotlin {
    jvm('jvm1')
    jvm('jvm2')

    sourceSets {
        commonMain { dependencies { ... } }

        commonTest {
            dependencies {
                implementation kotlin('test-annotations-common')
            }
        }

        jvm1Main {
            dependsOn commonMain

            dependencies { ... }
        }

        jvm2Main {
            dependsOn commonMain

            dependencies { ... }
        }

        jvm2Test {
            dependsOn commonTest

            dependencies {
                implementation kotlin('test')
                implementation kotlin('test-junit')
            }
        }
    }
}
However, running
./gradlew build
tries to compile
commonTest
through both
jvm1Test
and
jvm2Test
, and fails since
jvm1Test
doesn't have any test dependencies. Is there a way to disable
jvm1Test
or decouple it from
commonTest
?
e

Erik Christensen

07/09/2020, 11:21 PM
There's an automatic dependency on commonTest for any target created using
jvm()
. I don't think you can remove a
dependsOn()
relation -- seems like a bad thing to try doing even if it can be done. Anything in commonTest is supposed to be able to run on all targets that you're building. Is there a reason why you want to build jvm1, but not run tests on it?
a

andymin

07/10/2020, 1:28 AM
jvm1 uses some libraries that only work with specific hardware (this is code for a robot), so jvm2's purpose is to "simulate" some aspects to be able to run unit tests. perhaps i can override the build task to call assemble and jvm2Test?
e

Erik Christensen

07/10/2020, 1:47 AM
You can probably just disable the jvm1Test task.
tasks.getByName("jvm1Test").enabled = false
-- or something like that.
a

andymin

07/10/2020, 5:55 PM
Disabling compileTestKotlinJvm1 and jvm1Test worked, thanks!
👍 1