I have made a task called buildAssets, which takes a directory not located in main/resources, packs the assets, and spits them out into the resources directory. processResources task depends on this task.
Given these assets constitute a skin for a web app, a good build will always have some output (or previous output), not just a shell of a directory, but right now, the processResources task is seeing NO-SOURCE because the buildAssets task failed and there are no previously packed skin assets in its output folder, though the output folder still exists. Therefore, buildAssets isn’t being called at all (I don’t see it even showing up on the list of tasks checked) and processResources isn’t copying anything over to be put into the jar.
I tried changing the upToDateWhen for buildAssets outputs, but alas, if processResources doesn’t know that having nothing to copy is a bad thing, the build doesn’t want to even try to run buildAssets. I don’t see any kind of hooks to affect how input of the task computes into up to date checks.
I also suspect that processResources, in using the buildAssets task as from
in its copyspec, is only caring if there is a directory, not that there are files in it.
Going to tinker around and see if I’m missing something, but this seems like a common scenario I’d expect to see solutions out there and haven’t really seen others coming across this issue. Any pointers would be appreciated.
withProject(p) {
val buildutils by configurations.getting
val processResources by tasks.getting(Copy::class)
val main by sourceSets
tasks {
val buildAssets by creating(DefaultTask::class) {
group = "build"
description = "Build assets for jvm modules."
inputs.property("dest", "$buildDir/generated-resources/main/assets")
if (isAppProject() && isThatModule("${rootProject.name}-jvm"))
inputs.files(skin()).skipWhenEmpty()
inputs.files(main.resources.sourceDirectories).skipWhenEmpty()
outputs.dir(inputs.properties["dest"]!!)
doLast {
inputs.files.files.forEach {
javaexec {
args = listOf("-target=assets", "-src=${it.canonicalPath}", "-dest=${inputs.properties["dest"]!!}")
this.main = "com.acornui.build.BuildUtilKt"
classpath = buildutils
}
}
}
dependsOn(buildutils)
}
processResources.dependsOn(buildAssets)
processResources.from(buildAssets)
}
}
Note: buildAssets tasks are being created during the configuration phase in a subprojects block of a normal build script. For more info, the enclosing property lambda is being delegated to extra properties (ExtraPropertiesExtension) in an applied script with shared build logic, then being pulled into scope within a normal buildscript (unapplied) in the subprojects block where it checks each subproject for whether it has a plugin applied by type. This technique works and has had no adverse effects on other, similar tasks.