This is a simple gradle plugin that can generate git properties via a generateGitProperties
task.
If you ask yourself "Why? there is already plugins out there that do this.". You are right!
This plugin was build specifically with the purpose of supporting gradles configuration-cache feature. If you don`t need this functionality, you might choose a more mature plugin.
Add the following dependency to your plugin block
plugins {
id("io.hndrs.git-properties") version "1.0.0"
}
The Plugin registers a generateGitProperties
task to the project.
If the project includes the Gradle-Java-Plugin the generateGitProperties
task will be attached to the
classes
lifecycle task if the java plugin is present
When the task is not configured
- it is assumed that a
.git
folder is present in the root of the project. - the build will fail when an error occurs during the properties generation unless the
--continue-on-error
option is provided - the output file is
resources/main/git.properties
The task can be configured the following way if the defaults are not applicable:
import io.hndrs.gradle.plugin.git.properties.GenerateGitPropertiesTask
tasks.withType(GenerateGitPropertiesTask::class.java) {
dotGitDirectory.set(File(".git"))
continueOnError.set(false)
output.set(File("resources/main/git.properties"))
}
File (build.gradle.kts)
As you may know, CI environments handle the git repository differently and probably only checkout detached HEADs This plugin handles the branch resolution for
- Github Actions
- Gitlab CI
- Travis CI
If you are using a different CI service you can provide the branch name via the branch-name
option
./gradlew generateGitProperties --branch-name=$CI_SPECIFIC_ENV
git.branch=main
git.build.host=localHost
git.build.user.email[email protected]
git.build.user.name=John Smith
git.commit.id=e2f8a7bb72036e7a7a03ba243ca0414914cdfa82
git.commit.id.abbrev=e2f8a7b
git.commit.message.full=Merge pull request #1 from hndrs/prepare-initial-release\n\nPreparation of first release. Covers important cache test cases and cleans up code
git.commit.message.short=Merge pull request #1 from hndrs/prepare-initial-release
git.commit.signed=true
git.commit.time=2023-05-24T21:42:38Z
git.commit.user.email[email protected]
git.commit.user.name=John Smith
git.remote.origin.url[email protected]:hndrs/gradle-git-properties-plugin.git