Skip to content

indra git

zml edited this page Jan 28, 2022 · 7 revisions

The net.kyori.indra.git plugin provides git repository information within the Gradle build. This is similar to the old grgit plugin, but lighter-weight, not as attached to Groovy language details, not hosted in JCenter, and more actively maintained.

indra-git is a standalone plugin, and can operate without using any of the other components of the Indra suite.

(since v2.1.0) indra-git can be applied to either projects, or settings files.

This plugin exposes most of its functionality within the indraGit extension, which is always available, even if the project is not within a git repository checkout. Generally, the extension's methods will aim to fail safely -- returning empty collections or null when a repository is not present.

A requireClean task is added that, when executed, will fail if the project is in a git checkout that has uncommitted changes.


Caution: There are some cases where functionality can be limited when using certain CI setups:

  • On GitHub Actions, a shallow checkout is performed by default. This will not include certain repository information, such as tags. This can be resolved by setting the fetch-depth option to 0
  • When using a Docker image on GitHub Actions, no git information will be available if git is not on the PATH inside the image itself. The checkout action will fetch using GitHub's download function rather than a real checkout.

indraGit extension methods

Method Description
isPresent() Whether the current project is in a git repository checkout
git() The JGit Repository the current project is in, or null
tags() A list of tag Refs pointing to all tags in the repository, or an empty list if not in a git repository
headTag() If HEAD is a tagged object, the tag that refers to the commit at HEAD, otherwise null
describe() What would be the output of git describe --tags --long, or null if not in a git repository
branchName() The name of the branch currently checked out, or null at a detached HEAD
branch() A Ref describing the currently checked out branch
commit() The ObjectId of the current commit at HEAD
applyVcsInformationToManifest(manifest) Add the commit and branch to a jar Manifest as the Git-Commit and Git-Branch attributes.