14
votes

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.

1
Both Gradle for jvm and Webpack for js can be configured to use the common resources.AlexO

1 Answers

0
votes

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)})