Slackbot
03/14/2023, 4:24 PMmelix
03/14/2023, 4:25 PMtask.getImage().convention(imageBuilder.map(t -> t.getOutputFile().get()));melix
03/14/2023, 4:25 PMmap with a .get() inside? Why don't you use flatMap instead? Well, I ask you. If I write:melix
03/14/2023, 4:26 PMtask.getImage().convention(imageBuilder.flatMap(BuildNativeImageTask::getOutputFile));melix
03/14/2023, 4:26 PMimageBuilder task) is not tracked anymore!melix
03/14/2023, 4:26 PMmelix
03/14/2023, 4:27 PMmelix
03/14/2023, 4:27 PMimageBuilder.map(t -> imageBuilder.flatMap(BuildNativeImageTask::getOutputFile).get())melix
03/14/2023, 4:27 PMmelix
03/14/2023, 4:28 PMflatMap was precisely designed to track inputs...Thomas Broyer
03/14/2023, 4:33 PMVampire
03/14/2023, 4:45 PMflatMap is not designed to preserve task dependencies.
map is.
With flatMap the provider is completely replaced by the provider you get from the lambda.
So flatMap only preserves task dependencies if the provider you return already has that task dependency, for example because it is an output property of a task where the task dependency got forwarded to.Vampire
03/14/2023, 4:46 PMand issues have been closed by the stale botthank god they changed it to just mark it as stale but not auto-close anymore currently. ๐
melix
03/14/2023, 4:48 PMthis method offers a convenient way of connecting together task inputs and outputs
melix
03/14/2023, 4:48 PMimageBuilder task to the input of another task.melix
03/14/2023, 4:49 PMmelix
03/14/2023, 4:49 PMgetOuputFile is defined as:
@Internal
public Provider<RegularFile> getOutputFile() {
return getOutputDirectory().flatMap(dir -> dir.file(getExecutableName()));
}Vampire
03/14/2023, 4:54 PM@Internal so the task property does not get propagated to it.
And the flatMap you do inside also removes the task dependency that would have been on getOutputDirectory() which I guess is @OutputDirectory. If you change that to a map it will probably have the task dependency.Vampire
03/14/2023, 4:55 PM@Internal
public Provider<RegularFile> getOutputFile() {
return getOutputDirectory().map(dir -> dir.file(getExecutableName()).get());
}
and then
task.getImage().convention(imageBuilder.flatMap(BuildNativeImageTask::getOutputFile));melix
03/14/2023, 4:56 PMVampire
03/14/2023, 4:57 PMgetOutputFile as output instead, with all the consequences. Then the dependency should be propagated to it from the task.melix
03/14/2023, 4:57 PMmelix
03/14/2023, 4:58 PMflatMap shouldn't drop task dependencies, but that there should be an explicit call to drop task dependencies in case that's really what you wantVampire
03/14/2023, 4:58 PMmelix
03/14/2023, 4:59 PMVampire
03/14/2023, 4:59 PMmelix
03/14/2023, 4:59 PMVampire
03/14/2023, 4:59 PMVampire
03/14/2023, 5:09 PMmap, how about:
@Internal
public Provider<RegularFile> getOutputFile() {
return getOutputDirectory().zip(getOutputDirectory().flatMap(dir -> dir.file(getExecutableName())), (a, b) -> b);
}
๐melix
03/14/2023, 5:10 PMVampire
03/14/2023, 5:11 PM