# How best to depend on a single file output by a subproject task

**URL:** <https://discuss.gradle.org/t/how-best-to-depend-on-a-single-file-output-by-a-subproject-task/48480>\
**Category:** Help/Discuss\
**Created:** [May 14, 2024, 3:53pm UTC](https://discuss.gradle.org/t/how-best-to-depend-on-a-single-file-output-by-a-subproject-task/48480 "2024-05-14T15:53:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mos20](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@mos20](https://discuss.gradle.org/u/mos20)\
**Post date:** [May 14, 2024, 3:53pm UTC](https://discuss.gradle.org/t/how-best-to-depend-on-a-single-file-output-by-a-subproject-task/48480/1 "2024-05-14T15:53:09Z")

</div>

I’m in the process of converting from a single-project build to a multi-project build. My build has a task that takes as an input the single file output of another task (an instance of `AbstractArchiveTask` in this case, FWIW). In my new multi-project build, these two tasks will be in different projects.

Following the advice in the user documentation on [sharing outputs between projects](https://docs.gradle.org/current/userguide/cross_project_publications.html), I’ve made the output of the producer task an artifact of its project. However, I’m not sure of the best way to declare the fact that the consumer depends on the artifact and that it must also be a single file.

Here’s what I have in my consumer (in ultra-distilled form, which I hope illustrates the question without losing anything important; full example [here](https://github.com/markslater/gradle-examples/tree/951fe5e9b52d5546e21a5be745c870af0cef0796)):

```kotlin
val myConfiguration: Configuration by configurations.creating

dependencies {
    myConfiguration(project(mapOf(
        "path" to ":subproject",
        "configuration" to "myFile",
    )))
}

task("useSubprojectArtefact") {
    inputs.files(myConfiguration)
    doLast {
        logger.info(myConfiguration.singleFile.readText())
    }
}

```

My question is: Is there a way to declare my task depends on `myConfiguration.singleFile` at configuration time, rather than depending on `myConfiguration` and then failing at execution time if it contains more than one file? Or is there a better way of getting hold of the output of a task that’s constrained to be a single file, when that task is in another project?

I found [this closed issue](https://github.com/gradle/gradle/issues/2947) which refers to a similar problem, and indicates that it’s fixed by file properties, but I can’t work out how to get this to work.

---

<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:** [May 14, 2024, 4:00pm UTC](https://discuss.gradle.org/t/how-best-to-depend-on-a-single-file-output-by-a-subproject-task/48480/2 "2024-05-14T16:00:15Z")

</div>

I think what you do is the right thing to do already.  
Except that I would not uses the map-y method, but `myConfiguration(project(path = ":subproject", configuration = "myFile"))`  
And that you should not use `task("...")` as that breaks [task-configuration avoidance](https://docs.gradle.org/current/userguide/task_configuration_avoidance.html).

Even if you could express at configuration time that you expect one file in that configuration,  
Gradle could at configuration time not determine whether there will be 0, 1, or multiple files in that configuration at execution time.

---

<div class="post-metadata">

**Author:** ![mos20](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@mos20](https://discuss.gradle.org/u/mos20)\
**Post date:** [May 16, 2024, 2:43pm UTC](https://discuss.gradle.org/t/how-best-to-depend-on-a-single-file-output-by-a-subproject-task/48480/3 "2024-05-16T14:43:08Z")

</div>

Thanks for the reassurance!
