# Update dependencies from within a custom task

**URL:** https://discuss.gradle.org/t/update-dependencies-from-within-a-custom-task/26075
**Category:** Help/Discuss
**Created:** [March 2, 2018, 9:41pm UTC](https://discuss.gradle.org/t/update-dependencies-from-within-a-custom-task/26075 "2018-03-02T21:41:39Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Norm](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/norm/32/1096_2.png) [@Norm](https://discuss.gradle.org/u/Norm)
#### Post date: [March 2, 2018, 9:41pm UTC](https://discuss.gradle.org/t/update-dependencies-from-within-a-custom-task/26075/1 "2018-03-02T21:41:40Z")

</div>

I hope this is an easy one. I have a custom task (written in Groovy) with options for the primary input and primary output files.

```
task myTask(type: MyCustomTask) {
  input("primary", "somefile")
  output("result", "someotherfile)
}

```

That’s fine, but of course I want Gradle to know about this dependency, so what I actually end up writing is

```
task myTask(type: MyCustomTask) {
  inputs.file "somefile"
  outputs.file "someotherfile"
  input("primary", "somefile")
  output("result", "someotherfile)
}

```

Which is annoying and redundant. Is there any way for the implementation of input() and output() to put their arguments into inputs and outputs automatically?

---

<div class="post-metadata">

### Author: ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)
#### Post date: [March 2, 2018, 10:45pm UTC](https://discuss.gradle.org/t/update-dependencies-from-within-a-custom-task/26075/2 "2018-03-02T22:45:58Z")

</div>

Of course, the `input(...)` and `output(...)` methods are your custom methods, they can delegate through to `TaskInputs` and `TaskOutputs` methods in a similar way to `CopyTask.from(...)` or `CopyTask.into(...)` etc

---

<div class="post-metadata">

### Author: ![sterling](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sterling/32/5395_2.png) [@sterling](https://discuss.gradle.org/u/sterling)
#### Post date: [March 3, 2018, 6:02pm UTC](https://discuss.gradle.org/t/update-dependencies-from-within-a-custom-task/26075/3 "2018-03-03T18:02:40Z")

</div>

You can use annotations to mark properties of your task as inputs/outputs:

[https://guides.gradle.org/implementing-gradle-plugins/#benefiting\_from\_incremental\_tasks](https://guides.gradle.org/implementing-gradle-plugins/#benefiting_from_incremental_tasks)

---

<div class="post-metadata">

### Author: ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)
#### Post date: [March 4, 2018, 11:05am UTC](https://discuss.gradle.org/t/update-dependencies-from-within-a-custom-task/26075/4 "2018-03-04T11:05:11Z")

</div>

Agreed, annotations are often less verbose than explicitly invoking TaskInputs/TaskOutputs methods
