Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
396 views
in Technique[技术] by (71.8m points)

unit testing - Can't access commonMain multiplatform classes from a jvm-only module

I have a project with following structure:

  • multiplatformmodule - contains a single kotlin class SomeMultiPlatformClass
  • jvmmodule - a pure jvm module which depends on multiplatformmodule

The problem is that within the jvmmodule I can't access any class from multiplatformmodule when running a test. I get java.lang.NoClassDefFoundError: com/example/multiplatform/multiplatformmodule/SomeMultiPlatformClass. IDE (Anroid Studio) also marks this class as unresolved. It builds, however, when the multplatformmodule classes are accessed from another multiplatform module.

Much more can be seen in the example project https://github.com/micHar/kmm-dependency-issues/tree/master.

question from:https://stackoverflow.com/questions/65830632/cant-access-commonmain-multiplatform-classes-from-a-jvm-only-module

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I cloned your repo and opened it with Intellij 2020.3.1 and it seems to resolve SomeMultiPlatformClass fine. I tried to run tests from the IDE, which didn't work for different reasons. When I changed the @Test to point to kotlin.test.Test the IDE also ran the tests fine.

enter image description here

https://github.com/kpgalligan/kmm-dependency-issues


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...