https://github.com/hndrs/gradle-git-properties-plugin
Gradle Git Properties Plugin with configuration-cache support
https://github.com/hndrs/gradle-git-properties-plugin
configuration-cache git gradle gradle-build gradle-cache gradle-configurations gradle-kotlin gradle-plugin kotlin spring-boot
Last synced: 8 months ago
JSON representation
Gradle Git Properties Plugin with configuration-cache support
- Host: GitHub
- URL: https://github.com/hndrs/gradle-git-properties-plugin
- Owner: hndrs
- License: mit
- Created: 2023-05-21T11:37:46.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-28T16:21:57.000Z (about 3 years ago)
- Last Synced: 2024-12-19T03:34:04.717Z (over 1 year ago)
- Topics: configuration-cache, git, gradle, gradle-build, gradle-cache, gradle-configurations, gradle-kotlin, gradle-plugin, kotlin, spring-boot
- Language: Kotlin
- Homepage:
- Size: 113 KB
- Stars: 13
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://plugins.gradle.org/plugin/io.hndrs.git-properties)
[](https://sonarcloud.io/dashboard?id=hndrs_gradle-git-properties-plugin)
[]()
[](https://github.com/sponsors/marvinschramm)
# Gradle Git Properties
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](https://docs.gradle.org/8.1.1/userguide/configuration_cache.html) feature.
If you don`t need this functionality, you might choose a more mature plugin.
### Using the Plugin
Add the following dependency to your plugin block
```kotlin
plugins {
id("io.hndrs.git-properties") version "1.0.0"
}
```
### GenerateProperties Task
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
### Default Configuration
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:
```kotlin
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)
### Behaviour on CI environments
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
```bash
./gradlew generateGitProperties --branch-name=$CI_SPECIFIC_ENV
```
#### Available Properties
```properties
git.branch=main
git.build.host=localHost
git.build.user.email=john.smith@gradlemail.com
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=john.smith@gradlemail.com
git.commit.user.name=John Smith
git.remote.origin.url=git@github.com:hndrs/gradle-git-properties-plugin.git
```