Resources are not copied from processedResources to classes

Hi there.
I am using org.jetbrains.kotlin.multiplatform to ultimately bring my library to Android and iOS. For now I stick to Android only and removed all iOS parts from my project. Most things work fine so far, but I really struggle to load my test files that I embed as resource into my jvmTest area.

Everything looks fine so far, IntelliJ IDEA highlights the resource folders as such, the classes compile and tests run. But only when I try to access the resources they are not available. From a build-output it seems like that the processedResources are not copied over to the “classes” where the class loader would expect the resources. When I copy over the resources from “processedResources” to “classes” the tests run as expected and the resources are loaded.

Is this issue known? Is there maybe a workaround I can apply to get my resources copied from the processedResources folder to the classes folder?

Here some facts on what I am doing:

After compilation I have this directory tree:

MyLib
|-- build
|   |-- classes
|       |-- kotlin
|       |   |-- jvm
|       |       |-- main
|       |           |-- myLib
|       |           |-- META-INF
|       |       |-- test
|       |           |-- myLib
|       |           |-- META-INF
|       |-- processedResources
|           |-- jvm
|               |-- test
|                   |-- Test.file <-- this file should get loaded
|-- src
    |-- jvmMain
        |-- kotlin
        |-- kotlin-gen
        |-- resources
    |-- jvmTest
        |-- kotlin
        |-- kotlin-gen
        |-- resources

My build.gradle looks like this:

plugins {
    id 'org.jetbrains.kotlin.multiplatform' version '1.3.40'
}
repositories {
    mavenCentral()
}
group 'net.mylib'
version '0.9.3'

apply plugin: 'maven-publish'
apply plugin: 'idea'

idea.module.generatedSourceDirs += file('src/jvmMain/kotlin-gen')
idea.module.generatedSourceDirs += file('src/jvmTest/kotlin-gen')
kotlin {
    jvm()
    sourceSets {
        jvmMain {
            dependencies {
                implementation kotlin('stdlib')
            }
            kotlin.srcDir("src/jvmMain/kotlin-gen")
        }
        jvmTest {
            dependencies {
                implementation kotlin('test')
                implementation kotlin('test-junit')
            }
            kotlin.srcDir("src/jvmTest/kotlin-gen")
        }
    }
}

configurations {
    compileClasspath
}

I load the resources like this:

var stream = MyTests::class.java.getResourceAsStream("/Test.file");
if (stream == null) {
    val allResources = String(TestPlatform::class.java.getResourceAsStream("/").readAllBytes())
    kotlin.test.fail("File not found, available: " + allResources);
}

Kind Regards
Daniel

1 Like

Hi, this looks like a known problem, please see https://youtrack.jetbrains.com/issue/KT-24463

Thanks a lot for referencing the related issue. Good to know that the problem is known and being addressed. I think I need to start searching more in youtrack as those kind of issues you can not find by Googling or on the usual Q/A platforms.