# Additional custom uptodate check for custom tasks

**URL:** <https://discuss.gradle.org/t/additional-custom-uptodate-check-for-custom-tasks/5784>\
**Category:** Old Forum Archive\
**Created:** [May 28, 2014, 3:58am UTC](https://discuss.gradle.org/t/additional-custom-uptodate-check-for-custom-tasks/5784 "2014-05-28T03:58:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![etiennestuder](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/etiennestuder/32/7153_2.png) [@etiennestuder](https://discuss.gradle.org/u/etiennestuder)\
**Post date:** [May 28, 2014, 3:58am UTC](https://discuss.gradle.org/t/additional-custom-uptodate-check-for-custom-tasks/5784/1 "2014-05-28T03:58:00Z")

</div>

Hi

I’ve declared a custom task and defined the inputs and outputs to ensure the uptodate check works properly. So far, so good.

Now, on top of these inputs/outputs conditions, I would like to add another custom condition that flags whether the task is uptodate or not. For example, this custom condition will return true if the current day is Sunday and false on all other week days.

Can I do this with Gradle today? If so, how can it be done? Please note that my custom condition should _not_ be applied exclusively but additive, like the inputs and outputs.

Thanks and regards, Etienne

---

<div class="post-metadata">

**Author:** ![Perryn\_Fowler](https://avatars.discourse-cdn.com/v4/letter/p/82dd89/32.png) [@Perryn\_Fowler](https://discuss.gradle.org/u/Perryn_Fowler)\
**Post date:** [May 28, 2014, 5:05am UTC](https://discuss.gradle.org/t/additional-custom-uptodate-check-for-custom-tasks/5784/2 "2014-05-28T05:05:00Z")

</div>

You can use the [upToDateWhen](http://www.gradle.org/docs/current/javadoc/org/gradle/api/tasks/TaskOutputs.html#upToDateWhen(groovy.lang.Closure)) method to programatically determine if a tasks outputs are up to date.

However for your example [task.onlyif()](http://www.gradle.org/docs/current/dsl/org.gradle.api.Task.html#org.gradle.api.Task:onlyIf(groovy.lang.Closure)) is probably a better fit (since the day of the week seems unlikely to actually affect whether a task is up to date)

For more info see 15.8 and 15.9 of the user guide [http://www.gradle.org/docs/current/userguide/userguide\_single.html#N10EC0](http://www.gradle.org/docs/current/userguide/userguide_single.html#N10EC0)

---

<div class="post-metadata">

**Author:** ![etiennestuder](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/etiennestuder/32/7153_2.png) [@etiennestuder](https://discuss.gradle.org/u/etiennestuder)\
**Post date:** [May 28, 2014, 4:29pm UTC](https://discuss.gradle.org/t/additional-custom-uptodate-check-for-custom-tasks/5784/3 "2014-05-28T16:29:00Z")

</div>

Hm, my challenge is more tricky. I want the inputs and outputs (based on directories) to be included in the uptodate check and I also want an additional condition to be included in the uptodate check. If any of them (inputs/outputs/custom) says that the task is outdated, the task should be run. The problem with task.onlyIf() is that it works exclusively, i.e. if it returns false, it does not matter if the inputs and outputs are ‘dirty’ or not (also, the task will be marked as skipped and not as uptodate).

If there is no API to add a custom condition that does not act exclusively in the decision whether the task is uptodate or not, I wonder if there is an API that allows me to check if the inputs and outputs of a given task are uptodate, something like boolean TaskManager.areInputsUptodate(task) (I’m making that API up for clarity). I guess Gradle must have this kind of API internally anyway to check the uptodate status of a task.

Note that using the weekday in my custom check is not my real use case, but I think it is a simple to understand example. In my real use case, I want to check the state of my database (on top of some config files declared as inputs and some generated source code declared as outputs).

Any help is appreciated!

---

<div class="post-metadata">

**Author:** ![etiennestuder](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/etiennestuder/32/7153_2.png) [@etiennestuder](https://discuss.gradle.org/u/etiennestuder)\
**Post date:** [June 1, 2014, 8:47am UTC](https://discuss.gradle.org/t/additional-custom-uptodate-check-for-custom-tasks/5784/4 "2014-06-01T08:47:00Z")

</div>

I got it working using the TaskOutputs#upToDateWhen API. I also created a new feature request to have an API TaskInputs#upToDateWhen.

[http://forums.gradle.org/gradle/topics/feature\_request\_provide\_a\_new\_api\_taskinputs\_uptodatewhen](http://forums.gradle.org/gradle/topics/feature_request_provide_a_new_api_taskinputs_uptodatewhen)

I consider this thread as ‘answered’.
