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

Showkase was not able to find the root class that youpassed to @ShowkaseScreenshot. Make sure that you have configured Showkase correctly. #338

Closed ss0930 closed 1 year ago

ss0930 commented 1 year ago

Hello,

I am getting the following error only when a module is applying com.google.devtools.ksp (used for something else)

error: com.airbnb.android.showkase.processor.exceptions.ShowkaseProcessorException: Showkase was not able to find the root class that youpassed to @ShowkaseScreenshot. Make sure that you have configured Showkase correctly.

showkase = “1.0.0-beta18”
showkaseProcessor = { module = "com.airbnb.android:showkase-processor", version.ref = "showkase" }
showkaseScreenshotTesting = { module = "com.airbnb.android:showkase-screenshot-testing", version.ref = "showkase" }
showkaseScreenshotTestingPaparazzi = { module = "com.airbnb.android:showkase-screenshot-testing-paparazzi", version.ref = "showkase" }

build.gradle

apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.devtools.ksp'
...

kapt {
  arguments {
    arg("skipPrivatePreviews", "true")
  }
}

dependencies {
  testImplementation libs.showkaseScreenshotTesting
  testImplementation libs.showkaseScreenshotTestingPaparazzi
  testImplementation libs.testParameterInjector
  kaptTest libs.showkaseProcessor
  implementation libs.showkase
  kapt libs.showkaseProcessor
  ...
}

Root Module class

@ShowkaseRoot
class MyRootModule : ShowkaseRootModule

Snapshot Test

@ShowkaseScreenshot(rootShowkaseClass = MyRootModule::class)
abstract class ComposeSnapshotTests : PaparazziShowkaseScreenshotTest {
    companion object : PaparazziShowkaseScreenshotTest.CompanionObject {
        override fun providePaparazzi(): Paparazzi = Paparazzi(maxPercentDifference = 0.01)
    }
}

I have 2 modules

Module A with the above config which throws the following error on build Showkase was not able to find the root class that youpassed to @ShowkaseScreenshot

Module B without apply plugin: 'com.google.devtools.ksp' builds successfully

The @RootModule class is in the main source set. I am not sure why it works for 1 module but not for the other. I saw same error in https://github.com/airbnb/Showkase/issues/212 but not sure if it applies. Could you please provide some insight?

KSP Migration

I tried migrating to ksp with the following changes from the above config :

ksp {
    arg("skipPrivatePreviews", "true")
}

ksp libs.showkaseProcessor
kspTest libs.showkaseProcessor

Module A fails with

Execution failed for task ':moduleA:compileDebugUnitTestKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction

Module B builds successfully

vinaygaba commented 1 year ago

@ss0930 would you be able to share a sample project where I can repro this

ss0930 commented 1 year ago

@vinaygaba turns out this issue was due to a unit test compilation error and coming from Showkase even though the stacktrace seemed to indicate that. Fixing the compilation error fixed this issue. Closing this.