GitHub Packages introduced features for hosting Maven packages for free, but these require credentials even for public ones.
This grade plugin allows you to add a maven repository from GitHub Packages in one line. It also comes with a default personal access token, allowing the use of public repositories without any extra setup (see Notes on automatic authentication).
Using the plugins DSL:
plugins {
id("io.github.0ffz.github-packages") version "1.x.x"
}
Using legacy plugin application:
buildscript {
repositories {
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath("gradle.plugin.io.github.0ffz:gpr-for-gradle:1.x.x")
}
}
apply(plugin = "io.github.0ffz.github-packages")
You may find it on Gradle's plugin plugin portal
Within Groovy, you may add a package repository as follows:
repositories {
maven githubPackage.invoke("owner/repo")
// Or for all packages under the owner/org
maven githubPackage.invoke("owner")
}
There is currently no support for further customization in Groovy.
Add the GitHub repo to the repositories block:
repositories {
githubPackage("owner/repo")
// Or for all packages under the owner/org
githubPackage("owner")
}
Use the githubPackages
blocks above repositories
to edit the template applied to every package below. Example to change credentials of every repo:
githubPackages {
credentials {
username = "name"
password = "token"
}
}
repositories {
githubPackage("owner/repo") //now with different credentials!
}
You may also modify each package declaration as you would a regular maven repository:
repositories {
githubPackage("owner/repo"){
name = "anotherName"
credentials {
username = "name"
password = "token"
}
}
}
It appears sharing a PAT is currently the encouraged solution, as seen by this post from a staff member on the GitHub community forms. In a worst case scenario, the plugin will send a detailed message explaining exactly how to set up a token.
- Generate a token at https://github.com/settings/tokens/new?scopes=read:packages&description=GPR%20for%20Gradle
- Open your global gradle.properties file at
~/.gradle/gradle.properties
- Add username and token:
gpr.user=<GITHUB NAME> gpr.key=<GENERATED TOKEN>
- You may need to restart your IDE
For more info see this GitHub docs page.
GITHUB_ACTOR
and GITHUB_TOKEN
will be used within GitHub workflows, unless the username and password are manually changed.
- Make extension functions work nicely with Groovy (feel free to open a PR for it)
- Archive this project if Github Packages improve support for maven