How to define a task without outputs?


(Meikel Brandmeyer) #1

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 without need for a sophisticated build.


(Peter Niederwieser) #2

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 }’.


(Meikel Brandmeyer) #3

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.


(Meikel Brandmeyer) #4

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


(Luke Daley) #5

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


(Björn Kautler) #6

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.”