Lazily compute gitHeadHash
ben-manes opened this issue · comments
For convenience I am currently applying and configuring the git-state plugin
on the root project. That makes it easy to use within templates, like putting the commit hash into a JAR manifest. This works perfectly, but I dislike that it resolves the hash on every time regardless of whether its used.
It seems like this would be a perfect usage of Groovy's lazy transform.
I'm not sure I understand what you want to achieve, or how...
I put the head-hash into project.ext.gitHeadHash and this is done if the plugin is applied. If you don't want/need it then don't apply the plugin. I think this is correct but if you know of a better/faster way please let me know.
To configure the task I need to apply the plugin to the project, e.g.
configure(checkGitState) {
git.requireClean = true
description = "Checks whether the repository is dirty."
}
That, however, causes the gitHeadHash
to be precomputed. I had thought that you could apply the @Lazy
annotation to the property so that it would be computed on first usage. Unfortunately it looks like I'm wrong...
I'll probably just remove the plugin from the top-level (so no task) and only apply it when creating the deployment artifacts, as you suggested.