Add symbol processor for configuration metadata - #51375
salatmaster wants to merge 3 commits into
Conversation
ae9a47e to
60d3b03
Compare
Add spring-boot-configuration-symbol-processor, a Kotlin Symbol Processing (KSP) processor that writes the configuration metadata of Kotlin types. It reuses the metadata model of the annotation processor, so the generated META-INF/spring-configuration-metadata.json is identical in format, and it lets a Kotlin project generate its metadata without kapt. The processor supports constructor binding and JavaBean binding, nested groups, @ConfigurationProperties on a method, actuator endpoints, descriptions taken from KDoc, deprecations, and the merging of META-INF/additional-spring-configuration-metadata.json. A type annotated with @ConfigurationPropertiesSource is described in a file of its own. Kotlin types are reported using their JVM names, so that a List<String> property is described as java.util.List<java.lang.String> as it is when the annotation processor runs. See spring-projectsgh-28046 Signed-off-by: Areg Iazychian <abstractcoderx@gmail.com>
Add the symbol processor to spring-boot-dependencies so that a project can declare it without having to specify its version. See spring-projectsgh-28046 Signed-off-by: Areg Iazychian <abstractcoderx@gmail.com>
Describe how to apply the symbol processor, the types that it supports, how to contribute additional metadata, and its limitations. Note that a module has to apply either the annotation processor or the symbol processor, as both write the same metadata file. See spring-projectsgh-28046 Signed-off-by: Areg Iazychian <abstractcoderx@gmail.com>
60d3b03 to
86bbb93
Compare
|
Thanks for the proposal. Unfortunately, we're not happy with the approach taken here as it duplicates a considerable amount of logic between the Java annotation processor and the proposed KSP support. Ideally, any KSP support should be as thin a layer as possible that deals with Kotlin specifics before delegating to an implementation written in Java that's shared between the Java annotation processor and the KSP support. The issue is pending design work as we don't know exactly how to do that or if it's even feasible. If it proves not to be feasible it's unlikely that we'll support KSP as the maintenance burden will be too great. |
Just noticed this after I'd made the previous comment. This is exactly what we'd prefer to see. If you'd like to make an alternative proposal that takes this approach, or explore its feasibility and comment on the issue with your findings, that would be great. |
|
Thanks for the feedback, @wilkinsona. I've explored the approach that you described and opened #51930 as an alternative proposal. It introduces a small language-neutral model in |
This adds
spring-boot-configuration-symbol-processor, a KSP processor that generates configuration metadata for Kotlin sources, as an alternative to running the annotation processor through kapt. It reuses the metadata model of the existing annotation processor, so the generatedMETA-INF/spring-configuration-metadata.jsonis identical in format.Besides removing the need for kapt, it fixes metadata that kapt currently loses. For a data class with Kotlin defaults:
kapt generates a stub with two constructors, the annotation processor can no longer deduce the bind constructor, and no properties end up in the metadata at all — only the group. The symbol processor describes both properties. KDoc on constructor parameters (
@property) is picked up as well, which kapt drops.Supported: constructor and JavaBean binding,
@DefaultValue,@Name, nested groups,@NestedConfigurationProperty,@ConfigurationPropertieson a method, actuator endpoints, deprecations, KDoc descriptions, merging ofadditional-spring-configuration-metadata.json, and@ConfigurationPropertiesSource.Known limitations, all covered in the new appendix section:
@DefaultValuestill works.Tests drive the processor through the KSP2 API directly, so there is no third-party test dependency. The processor is compiled against
symbol-processing-api2.3.0 and declares it ascompileOnly, so the KSP version stays under the user's control.I'm aware this is marked as pending design work, so please treat it as a concrete proposal rather than a finished feature — happy to rework it if you'd rather see a different shape, such as an abstraction shared with the annotation processor.
See gh-28046