Skip to main content

Installation

Step 1: Create access token for the repository and package


  • Get access to the repository https://github.com/silence-laboratories/silent-shard-artifacts from the Silence Laboratories team.
  • Create a personal access token at https://github.com/settings/tokens with the following scopes checked[✓] to access the repository, and it's associated GithubPackages through gradle.
    • Under repo -> [✓] public_repo
    • Under write:packages -> [✓] read:packages
      We can leave write:packages untouched/unchecked as we only need read access
    • It will end up looking like this : Two items checked everything else unchecked. See below. github_pat_checked_scopes

Step 2: Configure settings.gradle.kts

  • Add the following maven repo under the dependencyResolutionManagement -> repositories :

    Under

    dependencyResolutionManagement{
    //Other stuff
    repositories{
    //Add here the block shown below
    }
    //Other stuff
    }

    Add the following

    maven {
    url =
    uri("https://maven.pkg.github.com/silence-laboratories/silent-shard-artifacts")
    credentials {
    username = "github_username"
    password = "token_we_just_created"
    }
    }
    • Replace github_username with your github username(The one we used for creating token).
    • Replace token_we_just_created with the token we created.
  • Your final dependencyResolutionManagement block will look like this (along with your own configuration)

    dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
    google()
    mavenCentral()
    maven {
    url =
    uri("https://maven.pkg.github.com/silence-laboratories/silent-shard-artifacts")
    credentials {
    username = "github_username"
    password = "token_we_just_created"
    }
    }
    //Other private repos or other resolution configuration. Or maybe another maven repo.
    }
    }

Advanced: Keep credentials out of source control

Instead of hardcoding your username and token, store them in local.properties (gitignored by default):

gpr.user=your_github_username
gpr.token=ghp_your_personal_access_token

Then add a helper in settings.gradle.kts that reads from local.properties, Gradle properties, or environment variables:

val localPropertiesFile = file("local.properties")
val localProperties = java.util.Properties()
if (localPropertiesFile.exists()) {
localPropertiesFile.inputStream().use { localProperties.load(it) }
}

fun getCredential(key: String): String {
return localProperties.getProperty(key)
?: providers.gradleProperty(key).orNull
?: System.getenv("ORG_GRADLE_PROJECT_$key")
?: ""
}

Use it in the maven block:

maven {
url = uri("https://maven.pkg.github.com/silence-laboratories/silent-shard-artifacts")
credentials {
username = getCredential("gpr.user")
password = getCredential("gpr.token")
}
}

This is the pattern used by the reference example apps.

Step 4: Configure app level build.gradle.kts


Add the dependency:

implementation("com.silencelaboratories.silentshard:duo-initiator:0.0.17")

Your final dependencies block will look like this:

dependencies {
implementation("com.silencelaboratories.silentshard:duo-initiator:0.0.17")
//Your Other dependencies
}

Step 5: Gradle-Sync


  • Sync gradle with project files and that's it.