Does anyone know if it's possible to store image r...
# compose-web
l
Does anyone know if it's possible to store image resources in another gradle module?
o
Sorry, I don't know the answer or any more details about thisissue. I think this question is not only compose-related. Perhaps, asking at #javascript could worth a try
d
You can probably make this work by configuring your final project's js jar as a fat jar. That is, you configure it telling it to run through its runtime dependencies and add all of their resources into your own final jar.
Maybe experiment with something like this in your build script?
Copy code
tasks.named("jsJar", Jar::class.java).configure {
  val classpathProvider = configurations.named("jsRuntimeClasspath")
  inputs.files(classpathProvider)

  doFirst {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    from(classpathProvider.get().map { if (it.isDirectory) it else project.zipTree(it).matching(patterns) })
  }
}
c
Indeed this is a Kotlin/JS problem, not related to Compose. I had to do this for a project of mine, here's the result of the investigation: • Resources in dependencies are included the generated artifacts, but they are ignored by the downstream package • If the dependency is part of the same multi-project build, no artifact is built, so the files are not created So what you have to do depends on whether you want the files to be accessed in another project of the same build, or in an external project (e.g. you're making a library). To allow a project to access the resources of another local project, you can simply add a
Copy
task. Assuming project
:b
uses resources from project
:a
:
Copy code
// b/build.gradle.kts

val jsWorkspace = "${rootProject.buildDir}/js"
val jsProjectDir = "$jsWorkspace/packages/${rootProject.name}-${project.name}"

val kotlinNpmInstall by rootProject.tasks.getting(org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask::class)

val copyAResources by tasks.registering(Copy::class) {
    description = "Copies the resources from :a"
    
    from("$[project(":a").projectDir}/src/main/resources")
    into(jsProjectDir)

    dependsOn(kotlinNpmInstall)
}

val developmentExecutableCompileSync: Task by tasks.getting {
    dependsOn(copyAResources)
}
// also add the dependency for your production task
Full example: https://gitlab.com/opensavvy/decouple/-/blob/main/demo/web/build.gradle.kts#L35 To access resources declared in an external module, you can use a similar trick:
Copy code
// b/build.gradle.kts

val expandedArchives = "${rootProject.buildDir}/tmp/expandedArchives"
val jsProjectDir = "${rootProject.buildDir}/js/packages/${rootProject.name}"

val kotlinNpmInstall by rootProject.tasks.getting()

val configureAResources by tasks.registering(Copy::class) {
	description = "Copies the ressources of :a"

	from(expandedArchives) {
		include("/a-js-*/")
		exclude("/a-js-*/package.json", "/a-js-*/default", "/a-js-*/META-INF")
	}

	into(jsProjectDir)
	eachFile {
		path = path.substringAfter("/")
	}
	includeEmptyDirs = false

	dependsOn(kotlinNpmInstall)
}
Full example: https://opensavvy.gitlab.io/decouple/documentation/style/material/index.html
I have no knowledge whatsoever of Gradle plugins or how the Kotlin plugin is structured, but I would be interested in guidance in how to upstream this directly to the Kotlin plugin
Since all files are already bundled in the exported JARs by the publishing plugin (which to me would be the hard part), the only thing left to do is to configure downstream projects to automatically retrieve them