google / ksp

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

KSP doesn't see class as open when opened with `allopen` Gradle plugin #1576

Open MarkAmeryCurative opened 11 months ago

MarkAmeryCurative commented 11 months ago

If you use the allopen plugin to mark a class and its members as open, KSP doesn't seem to recognise that you've done so, at least when used in conjunction with Micronaut AOP.

For a minimal example:

I've created a demo project at https://github.com/MarkAmeryCurative/ksp-aop-bug-demo you can use to see the bug in action. Just clone the project and run ./gradlew compileKotlin, and you'll see this error:

$ ./gradlew compileKotlin

> Task :kspKotlin FAILED
e: [ksp] Originating element: bar
e: [ksp] /home/mark/ksp-aop-bug-demo/src/main/kotlin/com/example/Application.kt:19: Method defines AOP advice but is declared final. Change the method to be non-final in order for AOP advice to be applied.
e: Error occurred in KSP, check log for detail

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':kspKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.3/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 3s
1 actionable task: 1 executed

i.e. KSP sees the class as non-open even though it's being opened with allopen.

efemoney commented 11 months ago

I would imagine this is because ksp runs (its own task) before the actual kotlin compilation (where compiler plugins run). I am not sure what a solution would look like here tbh

MarkAmeryCurative commented 11 months ago

Kapt also runs before actual Kotlin compilation, but somehow manages to respect allopen. So looking at Kapt's code and seeing how they manage it might inspire a solution.

waveskimmer commented 10 months ago

I'm seeing the same issue.

EliasJorgensen commented 2 months ago

Just ran into this issue as well. It's been a bit over half a year, has there been any progress on this issue? 🙏