Another question: I am creating a plugin that gene...
# community-support
i
Another question: I am creating a plugin that generates a directory with some resource files in
/build/generated/resources
. I need to add this directory to the resource source set. As I understand I can do it like this:
Copy code
project.sourceSets.main.get().resources.srcDirs.add(outputDir.get().asFile)
But I don't know at what point at time should it happen. In the
@TaskAction
method?
e
no, that needs to be done at configuration time. the project model is not mutable at execution time
also assuming
outputDir
is a task property and also its only output, you should simply
Copy code
sourceSets.main { resources.srcDir(task) }
which will pick up both the output dir and the task dependency so that it is automatically built
i
Thanks, I got it to work with:
Copy code
project.afterEvaluate {
            sourceSets.named("main") {
                resources.srcDir(task.get().outputDir.get().asFile)
            }
inside the plugin.
e
no that is wrong
☝️ 1
there is no need for
afterEvaluate
and you are losing the task dependency by using
asFile
👆 2
as well as overly eagerly configuring the task
☝️ 1
i
oh, I fixed it, thanks @ephemient!