I have an issue copying the resources from build directory to output directory in a task under build.
However when I first run gradle clean build -x test
, there is no output
dir. But if I re-run again I can see the output
dir with the files.
I’m guessing when I first run the resources
dir might be empty. And also added “depends on
” for the task where we place files in resources dir. But still same issue.
How do we wait till resources
dir has all files and then gather the files form resources to output dir in the build.
Any suggestions.
Thanks!Preformatted text
You shouldn’t place files into the resources dir.
Your task should place the generated resource files into a directory in layout.buildDirectory.dir("xxx")
Don’t forget to declare the generated files / directory as output in your task.
If this isn’t possible add them at least to the tasks outputs
. (Same of course for the inputs
)
// Here is an example NpxTask where the task creates files in the webapp dir
// some lines specific to the NpxTask have been removed
val buildWebapp by tasks.registering(NpxTask::class) {
inputs.dir(project.fileTree("src").exclude("**/*.spec.ts"))
outputs.dir("${project.buildDir}/webapp")
Then add those generated files to your resources:
sourceSets {
java {
main {
resources {
// This makes the processResources task automatically depend on the buildResourcesTask one
srcDir(buildResourcesTask)
}
}
}
}
1 Like