This project provides a file called project.properties
on your classpath (sourceSets.main.output.resourcesDir
) that contains git and project information.
apply plugin: 'projectInfo'
The plugin will ensure that the jar
or war
plugin has already been applied.
Then inject the generateProjectPropertiesFile
task into your build
war.dependsOn generateProjectPropertiesFile
Optionally, you may configure the name of the project injected into the
project.properties
file, or set the git repository URL using the projectInfo
configuration Closure.
projectInfo {
projectName = 'my-custom-project-name'
repoUrl = 'custom-project.git'
}
The following properties are placed in the project.properties
file:
PROJECT_NAME
: Defaults to the name of your gradle project, but can be overriddenPROJECT_VERSION
: Version of project as defined by gradleREVISION
: The SHA-1 git hash of the latest commit on your git repoAUTHOR
: The name of the last committerEMAIL
: Email of the last committerDATE
: Date of the latest commitMESSAGE
: The 'short' version of the git commit message (up to the first LF)BRANCH
: The current branch of the repoURL
: The repository URL (defaults to null)This project will only re-generate the properties file if the latest commit hash to the repo differs from the one that already exists in the build directory. This allows UP-TO-DATE checking on your builds.
If you find this useful and would like to make it more generic or add additional functionality, please submit a pull request, or open an issue!