sourceSets {
resources {
srcDir generatedResourcesDir
}
}
taskB {
doLast {
copy { stuff into generatedResourcesDir }
}
}
jar {
dependsOn taskB
from generatedResourcesDir
}
when we execute jar task, it would display warning “Encountered Duplicate… DuplicatesStrategy.WARN”
is it the right way to do it? I did try to remove the “from generatedResourcesDir”, but it from times to times it missing generatedResources from taskB, what’s the recommend approach for this?
So the problem here is that you have the generated sources being added to the jar from two different places - once from the outputs of the processResources task and once from the output of taskB. This is why you get the warning about duplicates. You want the generated sources added to the jar from one place and one place only. The best way to do this I think is to declare the generatedResourcesDir as an output of taskB and then couple the sourceSet declaration directly to taskB. That will cause all appropriate task dependencies to be auto-wired and you can remove the explicit wiring on the jar task. This also has the semantic advantage of creating a direct relationship between the sourceSet and the task that generates its resources (rather than something indirect via generatedSourcesDir).