"recommended" approach for deferred/lazy configuration of a Copy task

i got a Copy task i want to initialize lazyily, i.e. it operates on variables that do not exist at configuration time. after some reading, it seems that general approaches are to configure the task in another task it dependsOn or via doFirst… is the following idea an “ok” way to defer the task configuration to runtime (i am aware of the unknown input/output downside)?

task(doIt(type: Copy)).doFirst {
    configure(it) {
        from unknownPropertyAtConfigurationTime
        into anotherPropertyKnownOnlyAtRuntime
    }
}

thanks for feedback, zyro

That will work, but it’s typically a “bad smell”. I guess the question would be why is the location of the files not known at configuration time? If the files are being generated/copied/created by another task, a better way to do it if possible is to have your copy.from use the outputs of the other task that is determining the location of the files. For instance:

task gen(type: Copy) {
    from 'somefile'
    into 'build/gen'
}
  task mycopy(type: Copy) {
    from gen
    into 'build/mycopy'
}