https://github.com/usefulness/licensee-for-android
Turn raw cashapp/licensee report into assets/Kotlin code that can be easily consumed from an Android app
https://github.com/usefulness/licensee-for-android
android apache gradle licensee licenses mit mit-license opensource
Last synced: about 1 month ago
JSON representation
Turn raw cashapp/licensee report into assets/Kotlin code that can be easily consumed from an Android app
- Host: GitHub
- URL: https://github.com/usefulness/licensee-for-android
- Owner: usefulness
- License: mit
- Created: 2023-11-10T18:19:39.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-05-29T00:25:55.000Z (11 months ago)
- Last Synced: 2024-05-29T01:21:48.649Z (11 months ago)
- Topics: android, apache, gradle, licensee, licenses, mit, mit-license, opensource
- Language: Kotlin
- Homepage:
- Size: 1.59 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - usefulness/licensee-for-android - Turn raw cashapp/licensee report into assets/Kotlin code that can be easily consumed from an Android app (Kotlin)
README
# licensee-for-android
[](https://github.com/usefulness/licensee-for-android/actions)
[](https://plugins.gradle.org/plugin/io.github.usefulness.licensee-for-android)
Turn raw [cashapp/licensee](https://github.com/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:
- [Gradle Plugin Portal](https://plugins.gradle.org/plugin/io.github.usefulness.licensee-for-android)
- [Maven Central](https://mvnrepository.com/artifact/io.github.usefulness/licensee-for-android)#### Apply the plugin
```groovy
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:
```groovy
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 package
- `enableResourceGeneration` - 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 add `licensee-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### Common recipes
#### Generate licensee information from any module
```groovy
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`:
```groovy
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`:
```groovy
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
```groovy
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](https://github.com/premex-ab/gross) which this plugin forked from.