airbnb / Showkase

🔦 Showkase is an annotation-processor based Android library that helps you organize, discover, search and visualize Jetpack Compose UI elements
https://medium.com/airbnb-engineering/introducing-showkase-a-library-to-organize-discover-and-visualize-your-jetpack-compose-elements-d5c34ef01095
Apache License 2.0
2.1k stars 107 forks source link

KSP compiler warning when using multi preview annotations #322

Closed JeremiahStephenson closed 3 months ago

JeremiahStephenson commented 1 year ago

When using ksp combined with multi preview annotations I am seeing a compiler warning like this:

w: [ksp] No dependencies are reported for ShowkaseMetadata_showkase_ which will prevent incremental compilation.

The custom annotation looks like this:

@Preview(
    name = PreviewConfig.PreviewDefaultSuffix,
    device = PreviewConfig.DefaultDevice,
    locale = PreviewConfig.DefaultLocale,
    uiMode = Configuration.UI_MODE_NIGHT_NO,
)
@Preview(
    name = PreviewConfig.PreviewDarkSuffix,
    group = PreviewConfig.PreviewNoSnapshotGroup,
    device = PreviewConfig.DefaultDevice,
    locale = PreviewConfig.DefaultLocale,
    uiMode = Configuration.UI_MODE_NIGHT_YES,
)
@Preview(
    name = PreviewConfig.PreviewScaledSuffix,
    group = PreviewConfig.PreviewNoSnapshotGroup,
    device = PreviewConfig.DefaultDevice,
    locale = PreviewConfig.DefaultLocale,
    uiMode = Configuration.UI_MODE_NIGHT_NO,
    fontScale = PreviewConfig.DefaultUpscale,
)
annotation class DefaultPreviews

What I think is happening is that KSP is picking up on the @Preview annotation over the custom annotation (like it would normally do for a compose preview) and generates a file based on it. But then something checks it later and realizes something is wrong since the generated code isn't tied to an actual preview.

vinaygaba commented 1 year ago

@JeremiahStephenson Is this only happening in the multi preview context? i.e can you confirm you aren't seeing this when you are not using multi-preview?

matejdro commented 1 year ago

I'm also experiencing something similar, but it is not related to the root module, not multiple annotations:

No dependencies are reported for MyRootModuleCodegen which will prevent incremental compilation.
ln-12 commented 11 months ago

@vinaygaba I can confirm that this happens with custom annotation classes. My annotations look like this:

import androidx.compose.ui.tooling.preview.Preview

@Preview(widthDp = 411, heightDp = 842)
annotation class PortraitPreview

@Preview(widthDp = 842, heightDp = 411)
annotation class LandscapePreview

@PortraitPreview
@LandscapePreview
annotation class OrientedPreviews

When I use @OrientedPreviews (or @PortraitPreview and @LandscapePreview respectively) on my previews, the warning already shown above will be printed out:

> Task :cmx:kspDebugKotlin
w: [ksp] No dependencies are reported for ShowkaseMetadata_showkase_some_path_previews_portraitpreview which will prevent
incremental compilation.
Please file a bug at https://issuetracker.google.com/issues/new?component=413107.
w: [ksp] No dependencies are reported for ShowkaseMetadata_showkase_some_path_previews_landscapepreview which will prevent
incremental compilation.
Please file a bug at https://issuetracker.google.com/issues/new?component=413107.

If I replace @PortraitPreview and @LandscapePreview with the @Preview(...) annotations, the warning is not shown.

jmartinesp commented 9 months ago

Yes, the issue seems to come from that generated metadata used to be able to automatically detect multi preview annotations in KSP through different runs in different modules. I modified the code in Showkase to only process annotations provided with multiPreviewType in KSP too, removing the intermediate step of generating ShowkaseMultiPreviewCodegenMetadata and this issue is gone and the custom annotations are working just fine, tested against our real project.

You can see my changes here, in case they help.

joshdmiller5 commented 7 months ago

@matejdro Did you have any luck resolving this issue coming from the RootModuleCodegen? Currently experiencing the same warning/issue causing our custom Jenkins job to fail

matejdro commented 7 months ago

No luck yet, but the warning does not seem to affect anything. Our jobs do not fail because of it.

vinaygaba commented 3 months ago

This has been fixed with the following change - https://github.com/airbnb/Showkase/pull/383