gh-cli-auth

GitHub CLI Auth Gradle Plugin

Kotlin Continuous Integration Gradle Plugin Portal Gradle Plugin Portal

  1. Overview
  2. Features
  3. Installation
  4. Usage
  5. Configuration Options
  6. CI Tips
  7. Troubleshooting
  8. Limitations
  9. Contributing
  10. License

Overview

Zero‑boilerplate access to GitHub Packages (Maven) for your organization.

This plugin family configures the GitHub Packages Maven repository for your org and provides credentials automatically from one of three sources (in order):

  1. Environment variable (name configurable, default GITHUB_TOKEN)
  2. Gradle property (key configurable, default gpr.token)
  3. GitHub CLI: parses gh auth status --show-token (requires read:packages, read:org)

[!NOTE] This allows you to onboard this plugin to existing production CI/CD pipelines with minimal changes, while also supporting local development via the GitHub CLI.

It works as a settings plugin (centralized repository management for the whole build) and/or a project plugin (per‑project repository + a ghCliAuth extension to read the token).

Features

Installation

You can use either plugin—or both together.

[!TIP] Recommendation: In multi‑module builds (or when using RepositoriesMode.FAIL_ON_PROJECT_REPOS), prefer the settings plugin to centralize repository configuration. The project plugin declares repositories at project level and may conflict with FAIL_ON_PROJECT_REPOS.

Kotlin DSL – settings.gradle.kts

plugins {
    id("io.github.adelinosousa.gradle.plugins.settings.gh-cli-auth") version "2.0.0"
}

Groovy DSL – settings.gradle

plugins {
    id 'io.github.adelinosousa.gradle.plugins.settings.gh-cli-auth' version '2.0.0'
}

With the settings plugin applied, your build will have:

B) Project plugin (per project)

Kotlin DSL – build.gradle.kts

plugins {
    id("io.github.adelinosousa.gradle.plugins.project.gh-cli-auth") version "2.0.0"
}

Groovy DSL – build.gradle

plugins {
    id 'io.github.adelinosousa.gradle.plugins.project.gh-cli-auth' version '2.0.0'
}

With the project plugin applied, your project will have:

Usage

1) Required: Tell the plugin which organization to use

Add this to your gradle.properties (root of the build):

gh.cli.auth.github.org=<your-organization>

2) Choose how you want to provide credentials

You can do nothing (and rely on the GitHub CLI path below), or pick one of these:

[!WARNING] If both ENV and Gradle property are absent, the plugin automatically falls back to the GitHub CLI route.

Configuration Options

Key / Surface Where to set/read Default Purpose
gh.cli.auth.github.org gradle.properties (required) GitHub Organization used to build the repo URL and name the repo entry (https://maven.pkg.github.com/<org>/*).
gh.cli.auth.env.name gradle.properties GITHUB_TOKEN Name of the environment variable the plugin checks first for the token.
gh.cli.auth.property.name gradle.properties gpr.token Name of the Gradle property the plugin checks second for the token (e.g., pass -Pgpr.token=... or define in properties).
gradle.extra["gh.cli.auth.token"] read in settings.gradle(.kts) n/a Token shared by the settings plugin for use by other settings logic/plugins.
ghCliAuth.token read in build.gradle(.kts) n/a Token exposed by the project plugin’s extension.
-Dgh.cli.binary.path=/path/to/gh JVM/system property auto‑detect Override the gh binary path used by the CLI fallback. Useful for custom installs (e.g., Homebrew prefix, Nix).

Token resolution order

ENV (name = gh.cli.auth.env.name, default GITHUB_TOKEN)
  └── if unset/empty → GRADLE PROPERTY (key = gh.cli.auth.property.name, default gpr.token)
        └── if unset/empty → GitHub CLI: gh auth status --show-token

GitHub CLI scopes (CLI fallback):

Below is the required scopes for the token retrieved via the GitHub CLI:

If the token lacks these scopes, the plugin will fail with an error message prompting you to refresh your authentication.

Repository that’s registered:

https://maven.pkg.github.com/<org>/* (name = <org>), with credentials automatically supplied by the selected token source.

[!NOTE] Note on username: when the CLI path is used, the plugin extracts your GitHub login and uses it as the repository credential username; when ENV/Gradle property is used, the username is left empty.

CI tips

Troubleshooting

Limitations

Contributing

PRs and issues are welcome! See CONTRIBUTING.md.

License

This project is licensed under the AGPL-3.0 License - see the LICENSE for details.