Legal Disclaimer: This product is NOT officially endorsed or certified by GitHub.
The trademarks are being referenced for identification purposes only, in terms of a nominative fair use.
The official GitHub repositories can be found there: @GitHub.
This Gradle plugin was inspired by this discussion
and it may count as another GitHub Developer Program contribution, as it is built for and with GitHub API.
It is also being used in this repository's workflow: androidx-github.
I've recycled some of the models from the Android Java implementation, as they're merely the same.
- It interacts with the GitHub Packages API.
- It can list and delete versions and packages.
The plugin source code can be swiftly installed into any Gradle project with git clone:
git clone https://github.com/syslogic/gpr-maintenance-gradle-plugin.git ./buildSrcPlugin io.syslogic.gpr.maintenance depends on maven-publish (it will be applied).
It can be set up in the buildscript block of the root project's build.gradle:
buildscript {
repositories {
maven {
name = "JitPack"
url = uri("https://jitpack.io")
}
}
dependencies {
classpath("io.syslogic:gpr-maintenance-gradle-plugin:<PLUGIN_VERSION>")
}
}Or in version-catalog gradle/libs.versions.toml:
[versions]
gpr_maintenance_plugin = "<PLUGIN_VERSION>"
[plugins]
gpr_maintenance = { id = "io.syslogic.gpr.maintenance", version.ref = "gpr_maintenance_plugin" }To be applied in a library module's build.gradle:
plugins {
// id("maven-publish")
// id("io.syslogic.gpr.maintenance")
alias(libs.plugins.gpr.maintenance)
}The credentials are either being picked up from file token.properties (format: username token).
When running in GitHub workflow, one has to declare these environmental variables, which are being picked up instead.
- name: 🐘 Publish AAR to GPR
env:
GITHUB_ACTOR: ${{ GITHUB.REPOSITORY_OWNER }}
GITHUB_TOKEN: ${{ SECRETS.GITHUB_TOKEN }}
run: |
chmod + ./gradlew
./gradlew --max-workers=2 :library:publishLibraryPublicationToGitHubPackagesRepository
ls -la ./library/build/outputs/aar | grep aarThe GprMaintenanceExtension can be configured with the following properties:
| Property | Description | Type | Default |
|---|---|---|---|
packageType |
The package-type to query; any of: npm, maven, rubygems, docker, nuget, container. |
String |
maven |
groupId |
The group of the package to look up. | String |
project group |
packageName |
The name of the package to look up. That's often the only config required. | String |
project name |
tokenProperties |
The absolute path to file token.properties, containing following format: <username> <token>. Valid string-separators are: , | and /. |
String |
null |
deleteOnConflict |
Delete conflicting package version upon publish. | Boolean |
false |
deleteLastVersion |
Delete the whole package, when attempting to delete the last version. | Boolean |
false |
listPackagesAfterPublish |
List all packages after publish. | Boolean |
false |
logHttp |
HTTP logging | Boolean |
false |
pageSize |
Paginated package Listing page-size (max value 100) |
Integer |
30 |
In Groovy build.gradle, the extension is being called gpr.
gpr {
tokenProperties = rootProject.file("token.properties").absolutePath
deleteOnConflict = true
deleteLastVersion = true
listPackagesAfterPublish = true
logHttp = false
}In Kotlin build.gradle.kts one has to use configure<?>().
configure<GprMaintenanceExtension> { /* ... */ }Configuration tokenProperties is optional, while providing the config file at the default location:
buildSrc/token.propertiesor the parent project directorybuildSrc/../token.properties.
> Configure project :library
| + 46168200 ~ 1.0.5 -> https://api.github.com/users/syslogic/packages/maven/io.syslogic.androidx-github/versions/46168200
> Task :library:gprPackageDel_46168200
> [GPR] package io.syslogic.androidx-github deleted.
> Task :library:gprPackageList
Package {id=2607064, name="io.syslogic.agconnect-publishing-gradle-plugin", packageType="maven", visibility="public", versionCount=1, url="https://api.github.com/users/syslogic/packages/maven/io.syslogic.agconnect-publishing-gradle-plugin"}
| + 46071972 ~ 1.4.2 -> https://api.github.com/users/syslogic/packages/maven/io.syslogic.agconnect-publishing-gradle-plugin/versions/46071972

