Skip to content

Instantly share code, notes, and snippets.

@prasad79
Last active January 3, 2020 13:20
Show Gist options
  • Save prasad79/4eb0cdcdbc66fefbc5b5a94b23b72a47 to your computer and use it in GitHub Desktop.
Save prasad79/4eb0cdcdbc66fefbc5b5a94b23b72a47 to your computer and use it in GitHub Desktop.
Publishing Android library to the GitHub Package Registry
apply plugin: 'maven-publish' // Apply this plugin at the top of your library build.gradle
def githubProperties = new Properties()
githubProperties.load(new FileInputStream(rootProject.file("github.properties"))) //Set env variable GPR_USER & GPR_API_KEY if not adding a properties file
def getVersionName = { ->
return "1.0.2" // Replace with version Name
}
def getArtificatId = { ->
return "sampleAndroidLib" // Replace with library name ID
}
publishing {
publications {
bar(MavenPublication) {
groupId 'com.enefce.libraries' // Replace with group ID
artifactId getArtificatId()
version getVersionName()
artifact("$buildDir/outputs/aar/${getArtificatId()}-release.aar")
}
}
repositories {
maven {
name = "GitHubPackages"
/** Configure path of your package repository on Github
** Replace GITHUB_USERID with your/organisation Github userID
** and REPOSITORY with the repository name on GitHub
*/
url = uri("https://maven.pkg.github.com/GITHUB_USERID/REPOSITORY")
credentials {
/** Create github.properties in root project folder file with
** gpr.usr=GITHUB_USER_ID & gpr.key=PERSONAL_ACCESS_TOKEN
** Set env variable GPR_USER & GPR_API_KEY if not adding a properties file**/
username = githubProperties['gpr.usr'] ?: System.getenv("GPR_USER")
password = githubProperties['gpr.key'] ?: System.getenv("GPR_API_KEY")
}
}
}
}
@shauvik
Copy link

shauvik commented Dec 27, 2019

Typo alert: . after 'maven-publish'

@prasad79
Copy link
Author

prasad79 commented Jan 3, 2020

Typo alert: . after 'maven-publish'

Corrected. Thank you Shauvik.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment