At last I have found a solution with the help of this document , in which all the tasks that are performed during the build, test, releaseetc. in a very concise form. Therefore, performing tasks clean, preBuilddepends on my copyTask, I can guarantee that the task of copying is started each time the project is built or cleaned.
But since I don’t want to run it during the build or cleanup process, but I want to run it when I run the tests, I defined a task that compiles unit test sources called compileReleaseUnitTestSources, but just mentioning it in build.gradle as
compileReleaseUnitTestSources.dependsOn(myCopyTask)
, gradle , , compileReleaseUnitTestSources, - . , afterEvaluate, , , , . , , build.gradle
afterEvaluate {
compileReleaseUnitTestSources.dependsOn(copyResDirectoryToClasses)
}
, dependsOn , /, , , gradle , , /.