Turn raw cashapp/licensee report into assets/Kotlin code that can be easily consumed from an Android app
- 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")
)
Available on:
plugins {
id("app.cash.licensee") version "x.y.z"
id("io.github.usefulness.licensee-for-android") version "{{version}}"
}
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
}
enableKotlinCodeGeneration
- Enables generating a static list of open source assets.generatedPackageName
- Generate kotlin code under given packageenableResourceGeneration
- Enables copying licensee report to asset(Android)/resource(JVM) directory, making it available under 'resourceFileName' name.resourceFileName
- The name of the asset/resource file the licensee report gets copied to.singularVariantName
- The name of the build variant which all build variants will use, to show always the same licenses. (i.e."paidRelease"
)automaticCoreDependencyManagement
- Automatically addlicensee-for-android-core
core artifact as an implementation dependency for the generated code. The idea is to later use the same core artifact within a consumer project, and wire generated implementation via DI mechanism
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
}
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
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")
}
Huge thanks to premex-ab/gross which this plugin forked from.