I just figured out that task.inputs.property(“project version”, { project.version }) causes a task to do an up-to-date check on the project’s version. Nice!
My understanding is that gradle maintains a “task state cache” which is stored in the .gradle directory and which caches task states across build executions. In the above case you could include a task in your build chain which, using the settings in the original post, would only be executed when somebody changes the project version. This could for example send out a notification email from a continuous integration build or do some specific only-once-a-version maintenance on the build server etc.
The use I was putting it to was building a “launcher”, either windows exe or a mac app bundle. The launcher in both cases contains the version as a property and so I want the it to be rebuilt when I update the version, even if nothing else has changed in the source code. Would be very embarrassing to finally say, “yep 1.0 is ready to go” and then have the launcher say something ugly like “I am version 1.0-rc27-SNAPSHOT”. I am sure there are lots of other cases where the thing that is no longer “up to date” isn’t a file, but you still want to trigger a task to run.
An example is here, where the GenerateInfoPlistTask depends on the projects version.