I've just written another gradle plugin that that performs two tasks: - It injects a variable gitHeadHash into the project which contains the hash value of the current git commit. - It optionally checks if the repository is in a clean state. This means that there must not be any uncommited changes.
The code for that plugin is available at https://github.com/huxi/huxi-gradle-plugins/tree/master/git-state-plugin The dependency of the initial release is de.huxhorn.gradle:de.huxhorn.gradle.git-state-plugin:0.0.1 Documentation is currently lacking, i.e. not available at all at this point, so I'll quickly explain it a bit: The plugin adds an extension git that contains two boolean variables. project.git.requireClean (false by default) is used to enable checking of the repository state. The build fails if this is enabled and the repository is dirty. project.git.ignoreUntracked (false by default) can be used to relax the checking a bit. Untracked files are ignored and won't be considered dirty if enabled. Additionally, a new task checkGitState is created which isn't currently attached by default. The idea is to use something like processResources.dependsOn checkGitState manually. You can see the plugin in action in either the test at https://github.com/huxi/huxi-gradle-plugins/blob/master/git-state-plugin/src/test/groovy/de/huxhorn/gradle/git/GitStatePluginTest.groovy or in lilith. I added the plugin in this commit: https://github.com/huxi/lilith/commit/17ebd68347921314a7dbe6d7839f0340525f3660 (To build/test this, you need to build sulky first. So better just take a look or just test in one of your own projects. ;)) I have some questions, though: - Is adding the gitHeadHash to the project really the "right" way to get the hash value into the gradle build? I use this value to replace a placeholder during processResources so the generated artifact contains a definite information about the source used to create it. - Why can't I use "apply plugin: 'git-state'" instead of "apply plugin: de.huxhorn.gradle.git.GitStatePlugin"? I had a similar issue with my pgp-plugin and never figured out what went wrong. It does work in the test. That's what bothers me the most. - Should I attach the checkGitState task to some lifecycle automatically? What do you think? - Any other suggestions? Cheers, Joern. --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
