# Can Shared Build Services parameters receive tasks outputs as inputs?

**URL:** <https://discuss.gradle.org/t/can-shared-build-services-parameters-receive-tasks-outputs-as-inputs/43710>\
**Category:** Help/Discuss\
**Created:** [August 21, 2022, 9:48am UTC](https://discuss.gradle.org/t/can-shared-build-services-parameters-receive-tasks-outputs-as-inputs/43710 "2022-08-21T09:48:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![LikeTheSalad](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/likethesalad/32/10829_2.png) [@LikeTheSalad](https://discuss.gradle.org/u/LikeTheSalad)\
**Post date:** [August 21, 2022, 9:48am UTC](https://discuss.gradle.org/t/can-shared-build-services-parameters-receive-tasks-outputs-as-inputs/43710/1 "2022-08-21T09:48:20Z")

</div>

Hi! I’d like to know if a [Shared Build Service](https://docs.gradle.org/current/userguide/build_services.html) can receive a task’s output as its input, and that’d ensure that said task will always run before the service is created?

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [August 21, 2022, 8:20pm UTC](https://discuss.gradle.org/t/can-shared-build-services-parameters-receive-tasks-outputs-as-inputs/43710/2 "2022-08-21T20:20:28Z")

</div>

Doesn’t seem so.  
I tried with this:

```nohighlight
interface FooParams : BuildServiceParameters {
    val bar: RegularFileProperty
}
abstract class Foo : BuildService<FooParams>
abstract class Baz : DefaultTask() {
    @get:OutputFile
    abstract val out: RegularFileProperty
    @TaskAction
    fun doIt() {
        out.get().asFile.writeText("bam")
    }
}
val baz by tasks.registering(Baz::class) {
    out.set(layout.buildDirectory.file("baz.txt"))
}
val fooService = gradle.sharedServices.registerIfAbsent("foo", Foo::class) {
    parameters {
        bar.set(baz.flatMap { it.out })
    }
}
val bam by tasks.registering {
    usesService(fooService)
    doLast {
        println(fooService.get().parameters.bar.get().asFile.readText())
    }
}

```

and run task `bam`.  
No tasks other than `bam` were run and it complained that the file does not exist.  
But maybe that would be a candidate for a feature request on GitHub, especially if you can describe a proper use-case.

---

<div class="post-metadata">

**Author:** ![LikeTheSalad](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/likethesalad/32/10829_2.png) [@LikeTheSalad](https://discuss.gradle.org/u/LikeTheSalad)\
**Post date:** [August 22, 2022, 7:35am UTC](https://discuss.gradle.org/t/can-shared-build-services-parameters-receive-tasks-outputs-as-inputs/43710/3 "2022-08-22T07:35:30Z")

</div>

I see, many thanks for checking! - I got some similar results but I was wondering if I was doing something wrong so I wanted to double check here 🙂 my use case might not be too common though, basically there is one task, that I believe uses the Worker API to have many instances running in parallel, that I don’t create and don’t have control over, but it has an API that allows me to run my code as part of its execution, so this task is in between Gradle’s APIs and my code, but I need some other tasks to run prior to my code, which is in a Build Service so that it can be reused across all the instances of the task that I don’t control, and so far I haven’t found a way to do so.

I’ll create a ticket anyway to see if that could be useful for other people too.

Thanks.
