Skip to content

Instantly share code, notes, and snippets.

@prasad79
Last active August 8, 2024 23:29
Show Gist options
  • Save prasad79/d67c2a0e867387431eda2691dbcd25d2 to your computer and use it in GitHub Desktop.
Save prasad79/d67c2a0e867387431eda2691dbcd25d2 to your computer and use it in GitHub Desktop.
Publishing Android libraries to GitHub Packages using Kotlin DSL Gradle Scripts
import java.io.FileInputStream
import java.util.*
plugins {
id("com.android.library")
kotlin("android")
kotlin("android.extensions")
id("maven-publish")
}
repositories {
jcenter()
}
android {
compileSdkVersion(29)
defaultConfig {
minSdkVersion(23)
targetSdkVersion(29)
versionCode = 1
versionName = getVersionName()
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
}
/**Create github.properties in root project folder file with gpr.usr=GITHUB_USER_ID & gpr.key=PERSONAL_ACCESS_TOKEN**/
val githubProperties = Properties()
githubProperties.load(FileInputStream(rootProject.file("github.properties")))
fun getVersionName(): String {
return "1.0.2" // Replace with version Name
}
fun getArtificatId(): String {
return "sampleAndroidLib2" // Replace with library name ID
}
publishing {
publications {
create<MavenPublication>("gpr") {
run {
groupId = "com.enefce.libraries"
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/enefce/AndroidLibrary-GPR-KDSL")
credentials {
/**Create github.properties in root project folder file with gpr.usr=GITHUB_USER_ID & gpr.key=PERSONAL_ACCESS_TOKEN
* OR
* Set environment variables
*/
username = githubProperties.get("gpr.usr") as String? ?: System.getenv("GPR_USER")
password =
githubProperties.get("gpr.key") as String? ?: System.getenv("GPR_API_KEY")
}
}
}
}
dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61")
implementation("androidx.appcompat:appcompat:1.1.0")
implementation("androidx.core:core-ktx:1.1.0")
testImplementation("junit:junit:4.12")
androidTestImplementation("androidx.test.ext:junit:1.1.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.2.0")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment