Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does this work with commonMain? #20

Closed
mikeholler opened this issue Apr 19, 2022 · 7 comments
Closed

Does this work with commonMain? #20

mikeholler opened this issue Apr 19, 2022 · 7 comments

Comments

@mikeholler
Copy link

The README shows this snippet with commonTest, but I have a use-case for commonMain. Is it expected that this library will work there, too?

kotlin {
    sourceSets {
        val commonTest by getting {
            dependencies {
                implementation("com.goncalossilva:resources:<version>")
            }
        }
    }
}
@mikeholler
Copy link
Author

What I want to do:

kotlin {
    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("com.goncalossilva:resources:<version>")
            }
        }
    }
}

@goncalossilva
Copy link
Owner

No. The plugin only works with test resources. There are some reasons for this, such as resources not being packaged with binaries in most cases, or Karma only being available in testing.

What is your use case?

@goncalossilva
Copy link
Owner

Closing for now, but happy to discuss if there's follow-up. :)

@goncalossilva goncalossilva closed this as not planned Won't fix, can't repro, duplicate, stale Jun 9, 2022
@KevinnZou
Copy link

No. The plugin only works with test resources. There are some reasons for this, such as resources not being packaged with binaries in most cases, or Karma only being available in testing.

What is your use case?

I have a use case in which I need to read an HTML file in CommonMain and load it by WebView on each platform. Does this library support reading resources under the commonMain folder?

@goncalossilva
Copy link
Owner

It does not. I'm afraid the way resources are made available to some platforms is not suitable for any environment that's not a test environment. For example, it leverages Karma in JS, which is the test runner. It also leverages resources in JVM platforms, which includes Android, where they are discouraged.

Theoretically, it could be made to work in commonMain once #36 is done and if we exclude JS, although I feel that starts to deviate from the intended scope of the library.

It's not a scalable solution, but for a single HTML file, consider inlining it in a multi-line string. You can even automate generating that Kotlin file based on the original HTML file at build time.

@KevinnZou
Copy link

It's not a scalable solution, but for a single HTML file, consider inlining it in a multi-line string. You can even automate generating that Kotlin file based on the original HTML file at build time.

Thanks for your instruction! Could you provide more information on how to generate a Kotlin file based on an HTML file at build time?

@goncalossilva
Copy link
Owner

You can create a Gradle task that, during build time, reads the file, and uses it to generate a Kotlin file. I'm sure you'll find some examples online!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants