Any way to configure Gradle to always trust outputs.upToDateWhen (overriding task history check)?

Is there any way to override Gradle’s check for task history and always trust the result of ‘outputs.upToDateWhen’?

We have some tasks that execute some long-running database initialization scripts. These tasks have a simple query in the ‘outputs.upToDateWhen’ configuration. This works great to skip the tasks most of the time.

However, when developers first checkout the project from version control, the database init tasks always run on the first build because ‘No history is available for task’ even though the database is usually already initialized.

Do you have any inputs on that task?

No, there are no inputs defined for that task.

Here’s an obviously contrived example. The ‘initDB’ task is always up to date. To simulate a checkout from version control, I delete the .gradle directory. The task runs unless there is task history present in the .gradle directory.


task initDB() {
 outputs.upToDateWhen {true}
 doLast {
  println "Initializing database..."

Output when deleting .gradle directory and running:

> rmdir /s /q .gradle && gradle initDB --info
All projects evaluated.
Selected primary task 'initDB'
Tasks to be executed: [task ':initDB']
Executing task ':initDB' due to:
No history is available for task ':initDB'.
Initializing database...

You’d be better off using ‘onlyIf’ instead of up-to-date checking here.

Thanks. onlyIf works as I need. I can now see the difference between the ‘onlyIf’ and ‘outputs.upToDateWhen’ configurations.