micronaut-core: KSP: Problem with making @Singleton allOpen and ksp

Actual Behaviour

We have the following class and the project builds with kapt, allopen and micronaut 4.0.4

@Singleton
class SomeRequestValidator @Inject constructor(
    private val someService: SomeService
) : RequestValidator<SomeRequest> {
    ...
}
allOpen {
    annotations("jakarta.inject.Singleton")
    preset("micronaut")
}

If I try to migrate to ksp and use micronaut-core:4.0.6-SNAPSHOT and mictonaut-inject-kotlin:4.0.6-SNAPSHOT, I get

> Task :kspKotlin
e: [ksp] Originating element: SomeRequestValidator
e: [ksp] /<path>/SomeRequestValidator.kt:32: Cannot apply AOP advice to final class. Class must be made non-final to support proxying: <package>.SomeRequestValidator
e: Error occurred in KSP, check log for detail

Making the class explicitly “open” helps.

It looks like there is a hardcoded list of classes that are considered “shouldBeOpen”: https://github.com/micronaut-projects/micronaut-core/pull/9456/files#diff-8f68af29dd990607ef86587858c4f4e22a496688049ab10f74029a93149206ebR136 It would be great if we can add to it through grade configuration the same way allOpen plugin can be configured.

Version

Micronaut 4.0.4 / 4.0.6-SNAPSHOT

About this issue

  • Original URL
  • State: open
  • Created 10 months ago
  • Comments: 17 (17 by maintainers)

Most upvoted comments

I will take a look what can be done for the method level interceptors

@yawkat Is there a tracking issue for KSP/all open plugin?