21

I am porting a maven JVM Kotlin project to a gradle multiplatform Kotlin project. After creating the default Kotlin multiplatform project from Intellij IDEA, I notice there is a resources directory, but the only way I know how to load from the resources directory is JVM specific (this.javaClass.classLoader.getResourceAsStream(name)).

My initial searching has not found a platform independent way to load a resource using Kotlin standard libraries. Is there something I am missing or is the resources directory useless in a common module? The reason I need it is to load test data run in both the javascript module and the jvm module.

Umesh P
  • 228
  • 2
  • 7
Sean
  • 311
  • 1
  • 6
  • Both [Gradle for jvm](http://stackoverflow.com/a/38982006/1941359) and [Webpack for js](http://stackoverflow.com/a/50739724/1941359) can be configured to use the common resources. – AlexO Jun 19 '19 at 18:13

1 Answers1

0

It seams that the common/resource folder is ignored. I used an extra java module to share resources between projects.

Since your javascript module probably has to load the resources from a server, the way you access them in kotlin has to differ from the java module.

In the JS module you can use this command to load a file from server:

Request("https://pastebin.com/raw/p58mH6Cd").text().then(onFulfilled = {println(it)})
FLUXparticle
  • 733
  • 6
  • 16
  • is it for Kotlin 1.2 or 1.3? – 4ntoine Jan 18 '19 at 08:32
  • 1
    @Fluxparticle is correct. Resources are in Kotlin Multiplatform are platform dependend. As of Kotlin Multiplatform 1.6.x resources needs to be handles within the concrete platform code. – wartoshika Jun 07 '22 at 13:04