Skip to content
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

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

Open
VahidGarousi opened this issue Sep 9, 2024 · 1 comment

Comments

@VahidGarousi
Copy link

VahidGarousi commented Sep 9, 2024

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:

  • KSP version: 2.0.20-1.0.25
  • Gradle version: 8.6.0
  • Kotlin version: 2.0.20
  • Operating System: Windows 11

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

@VahidGarousi VahidGarousi changed the title KSP Compilation Failure: Unresolved error.NonExistentClass during MarketDaoImpl and LocalDatasourceModule processing KSP Compilation Failure: Unresolved error.NonExistentClass during MarketDaoImpl and LocalDatasourceModule processing Sep 9, 2024
@danysantiago
Copy link
Member

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: #1912

Two workarounds I can think of:

  • Move SQLDelight into its own module, where it only has the .sql files and it is an api of your database module
  • Force the SQLDelight task to run before KSP and possibly add the SQLDelight generated sources directory as part of Kotlin Comilation sources (I think this is already done by SQLDelight plugin).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants