licensee-for-android

Turn raw cashapp/licensee report into assets/Kotlin code that can be easily consumed from an Android app
Features
- Access licenses report directly by a generated Kotlin code (accessible via static
io.github.usefulness.licensee.LicenseeForAndroid object)
- Read licensee report copied to projects assets directory in runtime (via
assetManager.open("licensee_artifacts.json"))

Installation
Available on:
Apply the plugin
plugins {
id("app.cash.licensee") version "x.y.z"
id("io.github.usefulness.licensee-for-android") version "{{version}}"
}
Configuration
Options can be configured in the licenseeForAndroid extension:
licenseeForAndroid {
enableKotlinCodeGeneration = false
generatedPackageName = "io.github.usefulness.licensee"
enableResourceGeneration = false
resourceFileName = "licensee_artifacts.json"
singularVariantName = null
automaticCoreDependencyManagement = true
}
Common recipes
Generate licensee information from any module
plugins {
id("com.android.application") // or `com.android.library`
id("app.cash.licensee")
id("io.github.usefulness.licensee-for-android")
}
licensee {
allow("Apache-2.0")
}
licenseeForAndroid {
enableKotlinCodeGeneration = true
enableResourceGeneration = true
}
Generate Kotlin code in Kotlin-only module using licensee output from a different module
DI based approach
app/build.gradle:
plugins {
id("com.android.application")
id("app.cash.licensee")
id("io.github.usefulness.licensee-for-android")
}
licenseeForAndroid {
enableKotlinCodeGeneration = true
}
+ provide LicenseeForAndroid object as Licensee interface using your DI framework
consumer/build.gradle:
plugins {
id("org.jetbrains.kotlin.jvm") // or any other module type
}
dependencies {
implementation("io.github.usefulness:licensee-for-android-core:${{ version }")
}
+ inject Licensee interface
Gradle based approach
plugins {
id("org.jetbrains.kotlin.jvm") // or any other module type
id("io.github.usefulness.licensee-for-android") apply(false) // do not generate licensee information for _this_ module
}
// Register custom, source-generating task, use `:app`'s `productionRelease` variant
def licenseeTarget = layout.buildDirectory.map { it.dir("generated/licensee") }
tasks.register("generateLicenseeKotlinCode", CodeGenerationTask) {
it.inputFile.set(
project(":app").tasks.named("licenseeAndroidProductionRelease")
.flatMap { it.outputDir.file("artifacts.json") }
)
it.outputDirectory.set(licenseeTarget)
it.packageName.set("io.github.usefulness.licensee")
}
// Make sources discoverable in IDE (https://youtrack.jetbrains.com/issue/KT-45161)
sourceSets.named("main") {
kotlin {
srcDir(licenseeTarget)
}
}
// Make them run on every compilation
tasks.named("compileKotlin") {
dependsOn("generateLicenseeKotlinCode")
}
Credits
Huge thanks to premex-ab/gross which this plugin forked from.