This message was deleted.
# community-support
s
This message was deleted.
m
I want to hook Copy task into Android Gradle Plugin lifecycle using this API
Copy code
/**
     * Add the output of a custom task to the list of source directories.
     *
     * The [Directory] is the output of a Task [TASK] that has been registered using the Gradle's Task
     * manager.
     *
     * The [Directory] is added last to the variant's list of source directories. In case there is
     * merging for the source type, the [Directory] will have the highest priority.
     *
     * @param taskProvider the [TaskProvider] returned by Gradle's Task manager when registering the
     * Task of type [TASK].
     * @param wiredWith the method reference returning the [TASK] task's output to use as a source
     * directory. The generated source directory location is automatically determined by the
     * Android Gradle Plugin
     */
    fun <TASK: Task> addGeneratedSourceDirectory(
        taskProvider: TaskProvider<TASK>,
        wiredWith: (TASK) -> DirectoryProperty
    )
But since Copy task doesn’t expose
DirectoryProperty
it seems impossible.
v
objects.directoryProperty().fileValue(copyTask.destinationDir)
?
m
Do I get it right that it will create DirectoryProperty pointing to the file passed to fileValue? AGP plugin will then use this property to set the directory where it wants the files to be generated, but that won’t change the underlying path in the CopyTask.
a
yeah it’s tricky to convert between files and directories. if your copy task is registered, then try this:
Copy code
val myCopyTask = tasks.register<Copy>("myCopyTask") {
  // ...
}

val myCopyTaskDir: DirectoryProperty = objects.directoryProperty()
myCopyTaskDir.set(
  layout.dir(myCopyTask.map { it.destinationDir })
)
and if it’s created, then create a provider
Copy code
val myCopyTask = tasks.create<Copy>("myCopyTask") {
  // ...
}

objects.directoryProperty()
  .set(
    layout.dir(provider { myCopyTask.destinationDir })
  )
v
How is that better than my version @Adam?
Why using the complex layout/dir/provider construct, when directory property now has the
fileValue
directly
Do I get it right that it will create DirectoryProperty pointing to the file passed to fileValue? AGP plugin will then use this property to set the directory where it wants the files to be generated, but that won’t change the underlying path in the CopyTask.
I'm not an Android developer, so no idea who sets what there. If the AGP plugin wants to use the property to set the value to a different value, it is probably not really possible in any good way.
m
If the AGP plugin wants to use the property to set the value to a different value, it is probably not really possible in any good way.
That’s exactly what it does. That’s why the property need to be part of the task so its respected.
v
Then you probably need to use an own custom task type that exposes a directory property and then use the
FileOperations.copy { ... }
closure in the tasks action
m
Right, that’s something I’ve been considering as well. I wanted to use this nice
expand
function of the copy task that allows to replace placeholder with the provided properties. But that will be easy to write on my own as well.
v
Everything the
Copy
task can do, the
copy
closure should also be able to
m
Oh indeed it does. Cool, thanks 😉
👌 1