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

Processor fails if runtime is missing from classpath #304

Closed evant closed 1 year ago

evant commented 1 year ago

We have a library project that we want to distribute and demo app. Therefore we don't want the library to depend on the showkase runtime, I'd expect only the annotations for the generated metadata would be sufficient. However, this is causing the processor to throw an error.

I'd expect this to work:

// lib/build.gradle

kspDebug "com.airbnb.android:showkase-processor:1.0.0-beta17"
debugImplementation "com.airbnb.android:showkase-annotation:1.0.0-beta17"
// app/build.gradle

ksp "com.airbnb.android:showkase-processor:1.0.0-beta17"
implementation "com.airbnb.android:showkase:1.0.0-beta17"

but it's failing with:

Caused by: java.lang.IllegalStateException: NO_EXPECTED_TYPE
    at org.jetbrains.kotlin.types.TypeUtils$SpecialType.getDelegate(TypeUtils.java:50)
    at org.jetbrains.kotlin.types.DelegatingSimpleType.getConstructor(SpecialTypes.kt:33)
    at org.jetbrains.kotlin.types.checker.KotlinTypePreparator.transformToNewType(KotlinTypePreparator.kt:19)
    at org.jetbrains.kotlin.types.checker.KotlinTypePreparator.prepareType(KotlinTypePreparator.kt:61)
    at org.jetbrains.kotlin.types.checker.KotlinTypePreparator.prepareType(KotlinTypePreparator.kt:16)
    at org.jetbrains.kotlin.types.TypeCheckerState.prepareType(AbstractTypeChecker.kt:38)
    at org.jetbrains.kotlin.types.AbstractTypeChecker.completeIsSubTypeOf(AbstractTypeChecker.kt:284)
    at org.jetbrains.kotlin.types.AbstractTypeChecker.isSubtypeOf(AbstractTypeChecker.kt:254)
    at org.jetbrains.kotlin.types.AbstractTypeChecker.isSubtypeOf$default(AbstractTypeChecker.kt:244)
    at org.jetbrains.kotlin.types.AbstractTypeChecker.isSubtypeForSameConstructor(AbstractTypeChecker.kt:488)
    at org.jetbrains.kotlin.types.AbstractTypeChecker.isSubtypeOfForSingleClassifierType(AbstractTypeChecker.kt:391)
    at org.jetbrains.kotlin.types.AbstractTypeChecker.completeIsSubTypeOf(AbstractTypeChecker.kt:294)
    at org.jetbrains.kotlin.types.AbstractTypeChecker.isSubtypeOf(AbstractTypeChecker.kt:254)
    at org.jetbrains.kotlin.types.AbstractTypeChecker.isSubtypeOf$default(AbstractTypeChecker.kt:244)
    at org.jetbrains.kotlin.types.checker.NewKotlinTypeCheckerImpl.isSubtypeOf(NewKotlinTypeChecker.kt:94)
    at org.jetbrains.kotlin.types.checker.NewKotlinTypeCheckerImpl.isSubtypeOf(NewKotlinTypeChecker.kt:82)
    at org.jetbrains.kotlin.types.expressions.DataFlowAnalyzer.checkTypeInternal(DataFlowAnalyzer.java:298)
    at org.jetbrains.kotlin.types.expressions.DataFlowAnalyzer.checkType(DataFlowAnalyzer.java:350)
    at org.jetbrains.kotlin.types.expressions.DataFlowAnalyzer.checkType(DataFlowAnalyzer.java:266)
    at org.jetbrains.kotlin.types.expressions.BasicExpressionTypingVisitor.visitAnnotatedExpression(BasicExpressionTypingVisitor.java:1651)
    at org.jetbrains.kotlin.types.expressions.BasicExpressionTypingVisitor.visitAnnotatedExpression(BasicExpressionTypingVisitor.java:1636)
    at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.visitAnnotatedExpression(ExpressionTypingVisitorDispatcher.java:434)
    at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher$ForDeclarations.visitAnnotatedExpression(ExpressionTypingVisitorDispatcher.java:47)
    at org.jetbrains.kotlin.psi.KtAnnotatedExpression.accept(KtAnnotatedExpression.java:34)
    at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.lambda$getTypeInfo$0(ExpressionTypingVisitorDispatcher.java:176)
    ... 142 more

workaround is to add:

debugCompileOnly "com.airbnb.android:showkase:1.0.0-beta17"
vinaygaba commented 1 year ago

@evant This is how you'd need to set it up to ensure that you are only adding showkase runtime to debug builds.

implementation "com.airbnb.android:showkase-annotation:1.0.0-beta18"
kspDebug "com.airbnb.android:showkase-processor:1.0.0-beta18"
debugImplementation "com.airbnb.android:showkase:1.0.0-beta18"

Let me know if this doesn't work for you. I think it shoudl!