How to load resources in new MPP



I try to load resources in a new MPP like"/sample/") without success. When i looking in the build folder, the resources are placed in the build/processedResources folder. But when i start an application with an IDEA run configuration this folder will not get applied to the classpath / classloader. The only workaround i see at the moment is to copy those resources with an custom Gradle copy taks to copy them into the build/classes/kotlin/jvm/main folder and execute this task before main start. Or do i anything wrong?




Having the same issue here.



If MPP is “multiplatform projects prototype” then it suppose to support JS target, right ?
In JS it is hard and invalid to perform synchronous blocking resource read, since all data fetch in JS is async.

Or am I miss something ?



Same issue as well.



Well, it does not have to be blocking. MPP probably needs some kind of internal way to load resources. For example using coroutines. It does not have to be done on a language level and could be implemented by libraries, but it requires some kind of support from the build system, meaning that resources must be loaded into the webpack bundle on JS.



Well, the thread starter initially requested it to be blocking.
If async is OK, then it should fit in classical multiplatform paradigm: mpp interface and platform implementations: for web, for jvm/android, and for iOS.

So the thread starter can

  • declare multiplatform (async) resource loading interface
  • implement it on required platforms.
  • package the resources in platform-specific way.


The problem as I see it is not in code, but in packaging and tooling. In JVM the content of resource directory is automatically included in jar. On JS, the resource should be somehow added to webpack build. On native, resources should probably come in a separate directory. Then there could be a platform specific resource getter that could load it from default directory for this platform. It should not be very hard to implement, but requires modifications to the gradle mpp plugin.



Well, if the problem is in the tool-chain and plugin, then it might be possible to file an YT issue describing the problem ?



Like this one: I have not found a universal proposal for common way to load resources. Probably I should write it later.



I hope will support cross-platform read-only Resources filesystem.



Sorry for my very late answer!

I think, my description of the problem was not clear enough when i read it now.

I think it’s neither related to JS / shared code or async / sync. It looks to me more like an IDE / classpath / build problem. I attached a very simple MPP project with just a properties file and a main class. If i execute the main function via IDEA run configuration, the resource will not be found. (78.2 KB)