# How to ensure configuration avoidance with tasks.named

**URL:** <https://discuss.gradle.org/t/how-to-ensure-configuration-avoidance-with-tasks-named/47314>\
**Category:** Help/Discuss\
**Created:** [December 23, 2023, 4:17pm UTC](https://discuss.gradle.org/t/how-to-ensure-configuration-avoidance-with-tasks-named/47314 "2023-12-23T16:17:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daveankin](https://avatars.discourse-cdn.com/v4/letter/d/3da27b/32.png) [@Daveankin](https://discuss.gradle.org/u/Daveankin)\
**Post date:** [December 23, 2023, 4:17pm UTC](https://discuss.gradle.org/t/how-to-ensure-configuration-avoidance-with-tasks-named/47314/1 "2023-12-23T16:17:44Z")

</div>

![image](https://global.discourse-cdn.com/gradle/original/2X/2/27ca577906e66c66b2c34cf645c46464be0476e3.png)

Considering the above code sample:

```gradle
tasks.named('integrationTest', Test).configure ({
    def laJar = project(':some-other').tasks.named('bootJar').get()
    it.dependsOn laJar
    it.systemProperty('laJar', laJar.outputs.files.singleFile.path)
} as Action)

tasks.named('integrationTest', Test) {
    def laJar = project(':some-other').tasks.named('bootJar').get()
    it.dependsOn laJar
    it.systemProperty('laJar', laJar.outputs.files.singleFile.path)
}

```

my question is do we have to use the configure method explicitly, or is the bottom/second format sufficient?

---

<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:** [December 23, 2023, 11:39pm UTC](https://discuss.gradle.org/t/how-to-ensure-configuration-avoidance-with-tasks-named/47314/2 "2023-12-23T23:39:45Z")

</div>

Regarding `named` and `configure`, the second is sufficient for task-configuration avoidance.

But your snippets have other problems.  
For example you should definitely not use `tasks.named` on another project, as that project might not yet be configured and it is highly problematic to reach into other project models like that.

And even worse, you break task configuration avoidance for that task by using `get()` on it and reach even further into the other projects model by accessing properties of that task which is also a very big no-go.

Read more about it and how to properly share things cross-project at [Sharing outputs between projects](https://docs.gradle.org/current/userguide/cross_project_publications.html).

---

<div class="post-metadata">

**Author:** ![Daveankin](https://avatars.discourse-cdn.com/v4/letter/d/3da27b/32.png) [@Daveankin](https://discuss.gradle.org/u/Daveankin)\
**Post date:** [December 24, 2023, 8:31pm UTC](https://discuss.gradle.org/t/how-to-ensure-configuration-avoidance-with-tasks-named/47314/3 "2023-12-24T20:31:52Z")

</div>

the `project(path: ':my-other-project', configuration: 'specificallyJustTheOneFileINeed')` notation is really weird. seems to be able to get me my data, i wonder if this also works for copying around bundled javascript folder as well

---

<div class="post-metadata">

**Author:** ![Daveankin](https://avatars.discourse-cdn.com/v4/letter/d/3da27b/32.png) [@Daveankin](https://discuss.gradle.org/u/Daveankin)\
**Post date:** [December 24, 2023, 8:51pm UTC](https://discuss.gradle.org/t/how-to-ensure-configuration-avoidance-with-tasks-named/47314/4 "2023-12-24T20:51:32Z")

</div>

implemented it this way - [attempt to implement "Sharing outputs between projects" · alexanderankin/side-projects@aa06d05 · GitHub](https://github.com/alexanderankin/side-projects/commit/aa06d05b776a594d1b83f4b3d1ffadece002f5ee) - curious to know if you would expect this part:

```gradle
artifacts.add('la', bootJar)

```

to automatically add the `bootJar` task as a dependency to run when this configuration is consumed.

---

<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:** [December 25, 2023, 1:11am UTC](https://discuss.gradle.org/t/how-to-ensure-configuration-avoidance-with-tasks-named/47314/5 "2023-12-25T01:11:49Z")

</div>

> i wonder if this also works for copying around bundled javascript folder as well

it works for any files you can imagine

> to automatically add the bootJar task as a dependency to run when this configuration is consumed.

Yes, you just do not consume it properly. 🙂

If you would wire the `la` configuration to some input files property, the implicit task dependency would be effective.

But you only use the configuration at configuration time to get the path.  
At that time you could not execute the task even if you would need to, as you are still in configuration phase, not yet at execution phase.

But even if you would use the `la` configuration at execution time it would not automatically trigger the necessary task, because now you are already at execution phase which is too late to schedule additional tasks, as the tasks to be executed in the execution phase are determined at the end of the configuration phase when the task graph is built.

How you do it in your concrete case depends mainly on one question. Should the integrationTest task rerun if that jar changes or not? If not, then you could simply do `dependsOn(configurations.la)` which would be an explicit depending on the implicit task dependencies of that configuration.

But usually and I strongly guess here too, the task should rerun if the file changes, so your configuration is erroneous anyway as you don’t declare the file as input file.  
If you replace the `dependsOn` with `inputs.files(configurations.la).withPropertyName('theTestedBootJar')`, then you get the necessary implicit task dependency and have the file properly declared as input. You might actually want to also set the path sensitivity for potential cache hits across worktrees for example.

---

<div class="post-metadata">

**Author:** ![Daveankin](https://avatars.discourse-cdn.com/v4/letter/d/3da27b/32.png) [@Daveankin](https://discuss.gradle.org/u/Daveankin)\
**Post date:** [December 25, 2023, 10:57pm UTC](https://discuss.gradle.org/t/how-to-ensure-configuration-avoidance-with-tasks-named/47314/6 "2023-12-25T22:57:24Z")

</div>

depending on the configuration works: `dependsOn(configurations.la)` (although went with `inputs.files(configurations.la)` to make re-running more reliable - didn’t even realize this doesn’t normally rerun on changes??).

marked as solution 🎉
