# How to define a task without outputs?

**URL:** <https://discuss.gradle.org/t/how-to-define-a-task-without-outputs/6490>\
**Category:** Old Forum Archive\
**Created:** [August 20, 2012, 8:53pm UTC](https://discuss.gradle.org/t/how-to-define-a-task-without-outputs/6490 "2012-08-20T20:53:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Meikel\_Brandmeyer](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/meikel_brandmeyer/32/156_2.png) [@Meikel\_Brandmeyer](https://discuss.gradle.org/u/Meikel_Brandmeyer)\
**Post date:** [August 20, 2012, 8:53pm UTC](https://discuss.gradle.org/t/how-to-define-a-task-without-outputs/6490/1 "2012-08-20T20:53:00Z")

</div>

How can I define a task without outputs, but only inputs? Use case: a test task which only depends on the input source, runs the tests and checks for failures. There is no output.

In fact I would assume, that a task without declared outputs is up-to-date only depending on the inputs. Gradle has a different opinion at the moment.

**EDIT:** Use case is a [small project](https://bitbucket.org/kotarak/vimtap/src/295d155dbe22/build.gradle#cl-31) without need for a sophisticated build.

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [August 20, 2012, 10:34pm UTC](https://discuss.gradle.org/t/how-to-define-a-task-without-outputs/6490/2 "2012-08-20T22:34:00Z")

</div>

The output of Gradle’s ‘Test’ task is the XML/HTML test report. In other words, if the inputs haven’t changed, tests will only get executed if the report has been deleted or tampered with.

In general, if you don’t declare any outputs, Gradle assumes that the task needs to be rerun every time (this is the safer assumption). You can override this with ‘myTask.outputs.upToDateWhen { true }’.

---

<div class="post-metadata">

**Author:** ![Meikel\_Brandmeyer](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/meikel_brandmeyer/32/156_2.png) [@Meikel\_Brandmeyer](https://discuss.gradle.org/u/Meikel_Brandmeyer)\
**Post date:** [August 21, 2012, 8:20am UTC](https://discuss.gradle.org/t/how-to-define-a-task-without-outputs/6490/3 "2012-08-21T08:20:00Z")

</div>

It’s not about the Java ‘test’ task. Completely unrelated.

I tried the ‘upToDateWhen’ approach but got some strange results. So I thought it was not what I wanted. Now that you mention it also, I tried again. Now everything works as expected and solves my problem.

---

<div class="post-metadata">

**Author:** ![Meikel\_Brandmeyer](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/meikel_brandmeyer/32/156_2.png) [@Meikel\_Brandmeyer](https://discuss.gradle.org/u/Meikel_Brandmeyer)\
**Post date:** [August 21, 2012, 8:22am UTC](https://discuss.gradle.org/t/how-to-define-a-task-without-outputs/6490/4 "2012-08-21T08:22:00Z")

</div>

Oeh. How do I flag this question as “answered”?

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [August 21, 2012, 8:25am UTC](https://discuss.gradle.org/t/how-to-define-a-task-without-outputs/6490/5 "2012-08-21T08:25:00Z")

</div>

Hi Meikel, only moderators can update the status with this software. I’ll update it. Thanks.

---

<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:** [September 24, 2012, 8:59am UTC](https://discuss.gradle.org/t/how-to-define-a-task-without-outputs/6490/6 "2012-09-24T08:59:00Z")

</div>

If that is how it is supposed to work there seems to be a bug. I declared “outputs.upToDateWhen { true }” but still get “Task ‘foo’ has not declared any outputs, assuming that it is out-of-date.”
