If you want to configure input files only when the task is called, use gradle.taskGraph.whenReady
.
gradle.taskGraph.whenReady {TaskExecutionGraph graph ->
if(graph.hasTask(tasks.copy)) {
def fromDir = rootProject.file('services/website/app/')
def toDir = rootProject.file('dist/app/')
tasks.copy.from = fromDir
tasks.copy.into = toDir
}
}
The argument of taskGraph.whenReady
is taskGraph
itself. If copy
task is not called, this taskGraph
doesn’t have task copy
. So this configuration is not performed.
I think the following topic will be helpful for your problem.