Is it possible to use the task state caching mechanics from settings.gradle?


(Matias Bjarland) #1

I am familiar with the mechanics of inputs and outputs for gradle tasks. When setup correctly, gradle can check the cache from the last build and determine whether or not a specific task needs to be run by looking at the input and output properties for that task.

I would be interested in using this caching mechanism to conditionally run some code in settings.gradle. Is this possible? I realize the settings.gradle file is run before the life cycle phase for executing tasks is properly setup, but perhaps there is a way to do this anyway using a bit of custom code?

Any help much appreciated.


(Matias Bjarland) #2

To clarify, I have some code in settings.gradle which does a somewhat time consuming analysis of the directory structure under the directory where the settings.gradle file lives. It then creates a multi project structure on-the-fly as a result of the analysis. As this code is run every time you run a gradle command in this project I would like to run the time consuming analysis only if the relevant files changed.

This is in functionality similar to what gradle does when displaying the UP-TO-DATE messages for tasks based on their inputs and outputs. Gradle internally implements a task history repository that stores the state of a specific task from the previous execution. So the question becomes, is it worth investigating using this caching mechanism from settings.gradle vs implementing a caching mechanism from scratch yourself?


(Adam Murdoch) #3

The up-to-date checking infrastructure is only available for tasks at the moment. We do want to make it generally useful at some point, so that you can mark up a piece of build logic that is potentially expensive and Gradle can take care of the up-to-date checks.

There are a couple of options. One is to make the infrastructure more general purpose. The other is to allow you to use tasks for build configuration. Personally, I think there is a lot of goodness in using tasks for configuration, and this is my preferred option.


(Luke Daley) #4

Matias, does this answer your question satisfactorily?


(Matias Bjarland) #5

Sorry for the late reply. Yes, I consider this question answered.

I would like to figure out a way to hack my way to using the current caching mechanics and will post something here if I get that up and running, but for now we can close this thread.


(Luke Daley) #6

Good luck with the hacking :slight_smile: