Tested on Java LTS versions from 11 to 26.
Tested on Gradle versions from 8.0 to 9.5.1.
plugins {
id 'name.remal.github-repository-info' version '1.0.2'
}
This Gradle plugin that provides functionality to access GitHub repository information directly from the build environment.
It can be useful for projects that need to load some GitHub repository information dynamically. This is how you can add Maven POM license using this plugin:
apply plugin: 'maven-publish'
publishing.publications.withType(MavenPublication).configureEach {
pom {
licenses {
license {
name = githubRepositoryInfo.licenseFile.map { it.license.name }
url = githubRepositoryInfo.licenseFile.map { it.htmlUrl }
}
}
}
}All the information is loaded lazily and cached during the build.
This plugin creates githubRepositoryInfo extension that provides the following
read-only
properties.
githubRepositoryInfo.repository- provides information about the repository itself (example)githubRepositoryInfo.licenseFile- provides information about the repository license file (example)githubRepositoryInfo.contributors- provides a list of repository contributors (example)githubRepositoryInfo.languages- provides a map of programming languages used in the repository with their byte size (example)
All these properties load data lazily
and cache the result in ./build/tmp/.cache/name.remal.github-repository-info directory.
To get updated data, you need to delete this cache directory.
Also, you can get or configure general GitHub connection settings via the following Property<String> properties.
These properties are automatically configured from GitHub Actions environment variables or remote URL in the .git/config file.
githubRepositoryInfo.githubApiUrl- GitHub API URL (default:https://api.github.com).githubRepositoryInfo.repositoryFullName- repository full name (e.g.,owner/repo).githubRepositoryInfo.githubApiToken- GitHub API authentication token. See the Configuration section.githubRepositoryInfo.githubServerUrl- GitHub URL (default:https://github.com). Not used by this plugin directly, but can be useful for constructing links.
For public GitHub repositories, the plugin should work without any additional configuration.
However, for private repositories or to increase the rate limits, you need to provide a GitHub token.
To configure a GitHub token for GitHub Actions,
set GITHUB_TOKEN environment variable for your GitHub Actions job:
- name: Run Gradle build
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: ./gradlew buildGITHUB_ACTIONS_TOKEN environment variable can be used instead of GITHUB_TOKEN.
To configure a GitHub token for local development,
add name.remal.github-repository-info.api-token property to your ~/.gradle/gradle.properties file:
name.remal.github-repository-info.api-token = <your github token here>This file is in the Gradle User Home directory, so it won't be committed.