Skip to content

Instantly share code, notes, and snippets.

@prasad79
prasad79 / build.gradle
Last active December 30, 2019 17:32
publish Android library to Github Packages - generate POM file with Transitive dependencies
publications {
bar(MavenPublication) {
groupId getGroupId()
artifactId getArtificatId()
version getVersionName()
artifact("$buildDir/outputs/aar/${getArtificatId()}-release.aar")
//generate .pom file with transitive dependencies
pom.withXml {
final dependenciesNode = asNode().appendNode('dependencies')
ext.addDependency = { Dependency dep, String scope ->
@prasad79
prasad79 / build.gradle.kts
Created December 17, 2019 16:03
Consuming an Android library from Github Packages using Kotlin DSL - configure repositories details
android{
repositories {
maven {
name = "GitHubPackages"
/* Configure path to the library hosted on GitHub Packages Registry
* Replace UserID with package owner userID and REPOSITORY with the repository name
* e.g. "https://maven.pkg.github.com/enefce/AndroidLibrary-GPR-KDSL"
*/
//url = uri("https://maven.pkg.github.com/UserID/REPOSITORY")
url = uri("https://maven.pkg.github.com/enefce/AndroidLibrary-GPR-KDSL")
@prasad79
prasad79 / build.gradle.kts
Last active December 17, 2019 15:49
Publishing Android library to Github Packages using Kotlin DSL - configure repositories details
publishing {
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") // Github Package
credentials {
//Fetch these details from the properties file or from Environment variables
@prasad79
prasad79 / build.gradle.kts
Created December 17, 2019 15:34
Publishing Android library to Github Packages using Kotlin DSL - customise publications
publishing {
publications {
create<MavenPublication>("gpr") {
run {
groupId = "com.enefce.libraries"
artifactId = getArtificatId()
version = getVersionName()
artifact("$buildDir/outputs/aar/${getArtificatId()}-release.aar")
}
}
@prasad79
prasad79 / build.gradle.kts
Last active April 4, 2024 19:18
Consuming libraries from Github Packages using Kotlin DSL
import java.io.FileInputStream
import java.util.*
plugins {
id("com.android.application")
kotlin("android")
kotlin("android.extensions")
}
/**Create github.properties in root project folder file with gpr.usr=GITHUB_USER_ID & gpr.key=PERSONAL_ACCESS_TOKEN**/
@prasad79
prasad79 / build.gradle.kts
Last active December 17, 2019 13:16
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")
}
@prasad79
prasad79 / build.gradle
Created November 15, 2019 09:34
using library from GitHub Package Registry
dependencies {
//consume library
implementation 'com.example:package' // Replace with the groupd id / package id and version number of library as required
....
}
@prasad79
prasad79 / build.gradle
Last active November 15, 2019 09:30
Fetching Android Library from Github Package Registry - Github Authentication code
def githubProperties = new Properties() githubProperties.load(new FileInputStream(rootProject.file(“github.properties”)))
repositories {
maven {
name = "GitHubPackages"
/* Configure path to the library hosted on GitHub Packages Registry
* Replace UserID with package owner userID and REPOSITORY with the repository name
* e.g. "https://maven.pkg.github.com/enefce/AndroidLibraryForGitHubPackagesDemo"*/
url = uri("https://maven.pkg.github.com/UserID/REPOSITORY")
credentials {
@prasad79
prasad79 / build.gradle
Last active January 3, 2020 13:20
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 = { ->
@prasad79
prasad79 / EventBus.kt
Created March 7, 2019 16:35
Kotlin coroutine-based event bus
import kotlinx.coroutines.experimental.DefaultDispatcher
import kotlinx.coroutines.experimental.channels.BroadcastChannel
import kotlinx.coroutines.experimental.channels.ReceiveChannel
import kotlinx.coroutines.experimental.channels.filter
import kotlinx.coroutines.experimental.channels.map
import kotlinx.coroutines.experimental.launch
import kotlin.coroutines.experimental.CoroutineContext
class EventBus {