-
Notifications
You must be signed in to change notification settings - Fork 32
Make artifacts.json available as an asset #412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
val capitalizedVariantName = variant.name.replaceFirstChar { | ||
if (it.isLowerCase()) { | ||
it.titlecase(ROOT) | ||
} else { | ||
it.toString() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val capitalizedVariantName = variant.name.replaceFirstChar { | |
if (it.isLowerCase()) { | |
it.titlecase(ROOT) | |
} else { | |
it.toString() | |
} | |
} | |
vval capitalizedVariantName = variant.name.replaceFirstChar { it.titlecase(ROOT) } |
While I do see a need, I don't think this is the solution.
=> I am okay to wire the outputs of the task to the android resources, even by default if R8/D8 can remove the file if unused. But if we do want to make the internal json file public available, we should also implement #410 to read the file. Or what is the real use-case? Should the user see the JSON file as is? => Or licensee could generate Kotlin code directly. |
What is the problem being android only? we support android specific stuff already. |
@jgbirk Like I said, I am okay to wire the outputs of the task to the android resources. But there is no need for a copy task, just use But I still don't understand the real use case. The end user of the app will see the json file as it? That's very uncommon. |
👍 Got it, I can do that. |
Now I got your use-case. |
Maybe I'm missing something, but just that is not creating the file. |
The reason for not using androidComponents.onVariants { variant ->
val capName = variant.name.replaceFirstChar { it.titlecase(Locale.ROOT) }
val licenseeTask = tasks.named<LicenseeTask>("licenseeAndroid$capName")
val copyArtifactsTask = tasks.register<Copy>("copy${capName}Artifacts") {
dependsOn(licenseeTask)
from(licenseeTask.map { it.jsonOutput })
// Copy artifacts.json to a new directory.
into(layout.buildDirectory.dir("generated/dependencyAssets/${variant.name}"))
}
variant.sources.assets?.addGeneratedSourceDirectory(licenseeTask) {
// Avoid using LicenseeTask::outputDir as it contains extra files that we don't need.
objects.directoryProperty().fileProvider(copyArtifactsTask.map { it.destinationDir })
}
} |
Yep, that served me as inspiration for this! |
Been thinking about this over the weekend, although I did think about this originally when the tool was built. My original intent was to parse this in a build plugin specific to our app, and either write out a new different JSON format or to generate Kotlin directly in the shape of our existing screen. The reason I wanted to do this was so that we could massage the data to look nicer while retaining the ability to fail the build if something was completely absent. One of the ways our Open Source attribution screen looks better than others is that it's far more human readable and using logical groupings of artifacts rather than a simple linear display. For example, we could choose to put Now we could simply embed the raw JSON and do all of this at runtime. There are no real performance or size concerns either way. We would lose the ability to fail the build if someone adds a dependency for which there is missing human-friendly data, though, although we obviously can always fall back to the machine data. |
@@ -68,6 +68,9 @@ abstract class LicenseeTask : DefaultTask() { | |||
@get:Input | |||
internal abstract val unusedAction: Property<UnusedAction> | |||
|
|||
@get:Input | |||
internal abstract val bundleAndroidAsset: Property<Boolean> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK it's not needed. And can you add a test without calling licensee?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah looks unused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a test, we probably want to enable the flag, build an APK (without explicitly running the task), and then maybe list its contents and look for the file? I'm not sure how thorough we really want to be here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just run assemble to test the task wiring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that covers everything except the relative path within assets which is pretty good. Since I think we will already need a dedicated test function, adding a quick path check inside the APK shouldn't be much more work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the test case, let me know if its good.
By calling
bundleAndroidAsset.set(true)
the plugin will copy the generatedartifacts.json
into the corresponding variantassets
folder.Closes #181