I have some problems setting up a dependency in a KMM project from a jvmmodule to the shared code. In short, the attached image shows what I want to do. The jvmmodule has a class called Test with a main method which uses code from the shared module.
I tried several solutions, none which are 100% working:
jvmmodule is configured as a regular kotlin jvm module which also has the application plugin enabled for testing purposes. The module has a project dependency on the shared module. When the Test class is ran using the ./gradlew :jvmmodule:run command everything works as expected. The output in the console should is ‘Hello from JVM’.
In IntelliJ or Android Studio the Greeting class in Test.kt cannot be found (not in the editor, compile error) and not at runtime. When running the classes from the gutter icon the following error occurs:
Caused by: java.lang.ClassNotFoundException: Greeting at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ... 1 more
- (https://github.com/jcraane/kmm-with-jvmmodule/tree/jvm-mp-lib) (inspired by kotlinconf app)
jvmmodule is configured as a multiplatform module with a single jvm target and a project dependency on the shared module. In this scenario code completion works in IntelliJ but when the Test class is run from the gutter icon the following error occurs:
Error: Could not find or load main class TestKt
Caused by: java.lang.ClassNotFoundException: TestKt
Is this the correct way of using shared code from a plain kotlin (kvm) module?