Update GitHub packages post

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-11-06 17:48:58 +05:30
parent bf4dff9297
commit bbb0583846
1 changed files with 40 additions and 4 deletions

View File

@ -9,7 +9,7 @@ tags = ["android", "gradle", "github", "packaging"]
title = "Publishing an Android library to GitHub Packages"
+++
>UPDATE(06/06/2020): The Android Gradle Plugin supports the Gradle Maven Publish plugin beginning version 4.0.0, so I've added the new process for this at the beginning of this guide. The previous post follows that section.
>UPDATE(06/06/2020): The Android Gradle Plugin supports Gradle's inbuilt `maven-publish` plugin since version 4.0.0, so I've added the updated process for utilising it at the beginning of this guide. The previous post follows that section.
GitHub released the Package Registry beta in May of this year, and graduated it to public availability in Universe 2019, rebranded as [GitHub Packages](https://github.com/features/packages "GitHub Packages"). It supports NodeJS, Docker, Maven, Gradle, NuGet, and RubyGems. That's a LOT of ground covered for a service that's about one year old.
@ -21,9 +21,11 @@ I've also created a [sample repository](https://github.com/msfjarvis/github-pack
NB: Grab a Personal Access Token from GitHub with the `write:packages` scope. You will be using this as authentication to deploy packages. I'll not delve deep into this, a Google search will point you in the right direction if you're not familiar with how to obtain one.
### New deployment steps
### For AGP >= 4.0.0
Since the `maven-publish` plugin now works with Android libraries, all you need to do is ensure you're on Gradle 6.5 and AGP 4.0.0, then configure as follows.
All you need to do is ensure you're on at least Gradle 6.5 and AGP 4.0.0, then configure as follows.
For Groovy:
```groovy
apply plugin: 'maven-publish'
@ -52,6 +54,40 @@ afterEvaluate {
}
```
For Kotlin:
```kotlin
plugins {
id("maven-publish")
}
afterEvaluate {
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/msfjarvis/github-packages-deployment-sample")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("USERNAME")
password = project.findProperty("gpr.key") ?: System.getenv("PASSWORD")
}
}
}
publications {
// Simple convenience function to hide the nullability of `findProperty`.
private fun getProperty(key: String): String {
return findProperty(key)?.toString() ?: error("Failed to find property for $propertyName")
}
create<MavenPublication>("release") {
from(components.getByName("release"))
groupId = getProperty("GROUP")
artifactId = "deployment-sample-library"
version = getProperty("VERSION")
}
}
}
}
```
You still need to set some properties in `gradle.properties`
```groovy
@ -61,7 +97,7 @@ VERSION=0.1.0-SNAPSHOT
And that should be it! You can check the migration commit [here](https://github.com/msfjarvis/github-packages-deployment-sample/commit/260fd3154fd393d3969afd048dc2c77d03619b1d).
### The old steps are as follows
### For AGP < 4.0.0
#### Step 1