I have a task with multiple outputs. Can I get a s...
# community-support
m
I have a task with multiple outputs. Can I get a single output from its property name?
Copy code
// How do I do this?
val file = task.outputs.getByName("fooBarOutput")
1
Alright, nevermind, just bumped into https://github.com/gradle/gradle/issues/21456 that I thumbed up already some time ago, life is all a giant endless cycle ♻️
v
If it is a "proper" task class, you should be able to get the respective output property. If it is an ad-hoc task you create yourself, just keep a reference to the output or make it a proper task class. If it is an ad-hoc task some plugin created, you might be at loss right now.
m
> If it is an ad-hoc task you create yourself, just keep a reference to the output I wanted it to carry the task dependency so I was like it should probably come from the task itself but indeed, I probably hack my way into
Copy code
taskProvider.map { fooBarOutput }
(For now I was using
files.filter {}
and filtering based on the name which works too but feels a bit weird)
v
If it is a proper output property, it will carry the task dependency, otherwise
flatMap
would also not help, as
flatMap
looses the task dependency of the provider you call it on
m
(edited for plain
map
, sorry I always get confused 😅 )
v
But as long as it is a proper task output and not within a
@Nested
where some bug is afair, it should just work.
👍 1
But yeah,
map
on the task also will work fine if it is not a proper output property. That is then not a hack, but the idiomatic way to go
👍 1
m
👍 Thanks!
👌 1