Slackbot
03/23/2023, 6:21 PMMarek
03/23/2023, 6:30 PM/**
* 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.Vampire
03/23/2023, 6:59 PMobjects.directoryProperty().fileValue(copyTask.destinationDir)
?Marek
03/23/2023, 7:02 PMAdam
03/23/2023, 7:07 PMval 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
val myCopyTask = tasks.create<Copy>("myCopyTask") {
// ...
}
objects.directoryProperty()
.set(
layout.dir(provider { myCopyTask.destinationDir })
)
Vampire
03/23/2023, 7:08 PMVampire
03/23/2023, 7:09 PMfileValue
directlyVampire
03/23/2023, 7:09 PMDo 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.
Marek
03/23/2023, 7:10 PMIf 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.
Vampire
03/23/2023, 7:11 PMFileOperations.copy { ... }
closure in the tasks actionMarek
03/23/2023, 7:13 PMexpand
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.Vampire
03/23/2023, 7:19 PMCopy
task can do, the copy
closure should also be able toMarek
03/23/2023, 7:20 PM