I have my resources in all over the source code… however all of them are in various sub directories with dir name res…
I wish test task picks all the files in res directory, where ever they are found in the root and copy them into resource build/resources/test/ folder as flattened file… (i.e. ignoring the source all the sub-directory info
but i tried it with copy task as follow and it work fine
tasks.register("copyResources",Copy){
from fileTree(layout.projectDirectory.dir("src/main/java/resources")).files
into layout.buildDirectory.dir("resources")
}
you can use that task and make other task depend on it till you get a better solution from more experience people
Thank You @justsomeone, I did not want to give an absolute path as I refactor a lot, hence wish to use ** notation so that, any refactoring, I am void of the extra burden of changing the paths in build scripts too.
That way, in ant the solution is refactoring friendly…this way…
what flatten does it irrespective of jar file in various sub-directories of lib, it would still copy them in ${test}/WEB-INF/lib folder, I am looking for similar solution in gradle…
nope… none are here to help… time to have our own tasks for this… gradle experts pl. share your expertise… on this simple and very trivial (as per ant style) need
Which is the same I told you, just that mine is the more object oriented way, while ChatGPT’s is the more String-y way, but well, I don’t expect any correct or good answer by it anyway from what I’ve seen so far.
In Kotlin DSL accessors are lazy by default.
So sourceSets.main does not give you the source set but a provider holding the source set.
The IDE will greatly help you there with the Kotlin DSL too, showing types and proper code completion.
If you really need the value eagerly, just add a .get(), otherwise for example use .map { ... }.
Don’t do that.
Never have multiple tasks with overlapping output directories.
That destroys up-to-date checks, it makes build cache impossible, it makes task output fingerprinting void.
It makes you need to define strange explicit dependencies to prevent ordering and dependency issues, …
Assuming those files are in src/test/resources, just configure the existing processTestResources task like I showed for the processResources before you said it is about test resources.
The biggest challenge with the standard directory structure i.e both test folder and main folder at the same level, on large projects managing respective test files is becoming too complex, hence we always create test folder under the respective source code directly…
This does give us great benefit as developers to not keep moving from one directory to another especially as we practice DevTests - based development (a kind of TDD, but does not enforce test to be written first and also include as many kinds of tests be written by developers including integration, e2e, mock etc)
As this is not a standard directory structure we have to bit more work at the script level, but that is one time but having such a directory structure saves us so much intellectual energy. We also make sure respective resources also are close to the respective main or test code, so that, no confusion of changing them when the code changes.
I also note your feedback of up-to-date checks, I agree this may also need to consider to further, especially in IDE context. Thank You for brining up this point.
Sure, both approaches of code layout have their pros and cons.
I’m not sure why you explained it, I didn’t say anything against it.
But nevertheless, you must not have multiple tasks with overlapping outputs.
The processTestResources task and your copyExtraTestResources0 have overlapping output directories, as processTestResources has $buildDir/resources/test as output directory and that is particularly bad.
Usually - as said already - you should instead configure the existing task to include the files you want like