google / ksp

Kotlin Symbol Processing API
https://github.com/google/ksp
Apache License 2.0
2.83k stars 265 forks source link

KSP Compilation Failure: Unresolved `error.NonExistentClass` during `MarketDaoImpl` and `LocalDatasourceModule` processing #2092

Open VahidGarousi opened 3 weeks ago

VahidGarousi commented 3 weeks ago

Description:

I'm encountering a KSP compilation failure where an unresolved error.NonExistentClass appears during the processing of MarketDaoImpl and LocalDatasourceModule. This issue occurs while attempting to process constructor and method parameters that reference a class that cannot be resolved.

Full error message:

Task :data:market-local:kspDebugKotlin FAILED
e: [ksp] InjectProcessingStep was unable to process 'MarketDaoImpl(error.NonExistentClass)' because 'error.NonExistentClass' could not be resolved.

Dependency trace:
    => element (CLASS): ir.composenews.localdatasource.database.MarketDaoImpl
    => element (CONSTRUCTOR): MarketDaoImpl(error.NonExistentClass)
    => type (EXECUTABLE constructor): (error.NonExistentClass)void
    => type (ERROR parameter type): error.NonExistentClass

If type 'error.NonExistentClass' is a generated type, check above for compilation errors that may have prevented the type from being generated. Otherwise, ensure that type 'error.NonExistentClass' is on your classpath.

The error suggests that a class required for dependency injection or some other processing step isn't being generated or included in the classpath, preventing compilation from succeeding.

Steps to reproduce:

  1. The class MarketDaoImpl depends on a type that either should be generated or resolved during compilation.
  2. The LocalDatasourceModule class in the DI module also fails to provide the correct class reference for dependency injection.
  3. I’ve ensured that necessary dependencies are included in the classpath, but the issue persists during the KSP processing step.

Environment:

If error.NonExistentClass is supposed to be generated by KSP, it seems that the class generation process is not occurring correctly, or there's an issue with the classpath.

I think this is the root of the error:

https://github.com/Kaaveh/ComposeNews/blob/1c9549eb47a3845179de7e4744dcdf62b30bdbb0/data/market-local/src/main/java/ir/composenews/localdatasource/di/LocalDatasourceModule.kt#L21

danysantiago commented 3 weeks ago

The issue is that MarketDaoImpl's constructor has a parameter of MarketDatabase a type that is generated by SQLDelight via its Gradle Plugin, where as Dagger is a KSP processor and these two are not wired correctly. This issue is a dupe of: https://github.com/google/ksp/issues/1912

Two workarounds I can think of: