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

Allow ConfigurationProcessor to work with Kotlin Symbol Processor #28046

Open
kkocel opened this issue Sep 17, 2021 · 16 comments
Open

Allow ConfigurationProcessor to work with Kotlin Symbol Processor #28046

kkocel opened this issue Sep 17, 2021 · 16 comments
Labels
status: pending-design-work Needs design work before any code can be developed theme: kotlin type: enhancement A general enhancement
Milestone

Comments

@kkocel
Copy link

kkocel commented Sep 17, 2021

The problem:
Currently, ConfigurationProcessor is backed by Annotation Processing. In Kotlin annotation processors can be used thanks to KAPT. Sadly KAPT does not work with JDK 16+ ( https://youtrack.jetbrains.com/issue/KT-45545 ). For Kotlin there are other processors like KSP ( https://github.com/google/ksp ), yet they do not rely on Java Annotation processing.

Proposed solution:
Provide an abstraction layer on ConfigurationMetadataAnnotationProcessor that will allow plugging in other processors.
Additionally provide an adapter for KSP.

@sdeleuze

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 17, 2021
@wilkinsona
Copy link
Member

wilkinsona commented Sep 17, 2021

Thanks for raising this.

Sadly KAPT does not work with JDK 16+ ( https://youtrack.jetbrains.com/issue/KT-45545).

My reading of that Kotlin issue is that KAPT does work with JDK 16+, but that it requires adding some JVM arguments to open up some of the JVM's internals to KAPT. Have I misunderstood the discussion?

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Sep 17, 2021
@kkocel
Copy link
Author

kkocel commented Sep 17, 2021

@wilkinsona You understood it better than I :) Yes, it's possible to break javac encapsulation using add-opens flags, but ihmo it's temporary (this flag can be taken away as with --illegal-access=permit in JDK 17).

I know that adding an abstraction layer over processors can add in additional complexity, but it can also be a safer solution (also please note that KSP authors claim that it's up to 2x faster than java annotation processors).

As with everything you should weigh your options as Spring maintainers.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Sep 17, 2021
@wilkinsona
Copy link
Member

The underlying problem with KAPT has now been fixed and will be part of the Kotlin 1.6 release. Rather than supporting a third-party alternative which, to me at least, has an unclear relationship with Kotlin and JetBrains, I think we should focus our efforts on working via KAPT. Thanks anyway for the suggestion.

@wilkinsona wilkinsona added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Oct 11, 2021
@bespaltovyj
Copy link

Hi, @wilkinsona.
The new Kotlin documentation says that kapt is in maintenance mode and new features are not planned.
And recommend using ksp(it should work faster).
image
Will you support ksp after this news?
If you don't mind, then I can start adding ksp support.

@snicoll snicoll added the for: team-meeting An issue we'd like to discuss as a team to make progress label Nov 2, 2021
@kkocel
Copy link
Author

kkocel commented Nov 2, 2021

@wilkinsona I asked about the relation of KSP and Kotlin: https://twitter.com/relizarov/status/1455452359669264384

So it looks like KSP is the way to go for Kotlin.

@wilkinsona wilkinsona added status: waiting-for-triage An issue we've not yet triaged and removed status: declined A suggestion or change that we don't feel we should currently apply labels Nov 8, 2021
@wilkinsona wilkinsona reopened this Nov 8, 2021
@philwebb philwebb added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged for: team-meeting An issue we'd like to discuss as a team to make progress labels Nov 10, 2021
@philwebb philwebb added this to the 2.x milestone Nov 10, 2021
@philwebb philwebb modified the milestones: 2.x, 3.x Aug 19, 2022
@stillya
Copy link

stillya commented Jan 10, 2023

Any updates? Kapt is horrible annotation processor, it will be great if spring will support ksp. I have all my backend on kotlin and I have to use Kapt and main problem is not even speed(but it's slow), kapt shadows errors constantly, invalidate build cache.

@hnljp
Copy link

hnljp commented Apr 20, 2023

Just for your information.
Google has created this abstraction layer over JavaAP and KSP.
https://github.com/androidx/androidx/tree/androidx-main/room/room-compiler-processing
https://mvnrepository.com/artifact/androidx.room/room-compiler-processing
It was originally created for room, but they are now using it for different projects.

@wilkinsona wilkinsona added the status: pending-design-work Needs design work before any code can be developed label Jul 26, 2023
@snv
Copy link

snv commented Oct 12, 2023

When trying to update to Java 21, i run into an IllegalAccessError again

java.lang.IllegalAccessError: superclass access check failed: class org.jetbrains.kotlin.kapt3.base.javac.KaptJavaCompiler (in unnamed module @0x59db8216) cannot access class com.sun.tools.javac.main.JavaCompiler (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.main to unnamed module @0x59db8216

Since kapt keeps breaking every now and then, it would be really great if spring moved away from using it.

@alwyn
Copy link

alwyn commented Nov 16, 2023

I have been trying to use the usual workarounds on 21 with no success. If anyone has it working, please let me know.

@ajgassner
Copy link

I have been trying to use the usual workarounds on 21 with no success. If anyone has it working, please let me know.

The fix will be backported to Kotlin 1.9.21, see https://youtrack.jetbrains.com/issue/KT-60507
In the meantime you have to use JDK 20 or 17 LTS, you decide.

@AlexeyTsvetkov
Copy link

Slightly offtopic: there is a chance you don't actually need the configuration annotation processor at all. If you use Intellij IDEA Ultimate (I don't think that Community ever supported Spring configuration code insight), starting from 2023.2 Intellij does not rely on the metadata generated by the Spring boot configuration annotation processor. Other IDEs still might require it. I want to share this, because I was completely unaware of this until today (despite working at JetBrains), and removing KAPT improved our clean build times by 36%, incremental build times by up to 50%.

@deejay1
Copy link
Contributor

deejay1 commented May 24, 2024

@AlexeyTsvetkov this still leaves the topic of the autoconfigure processor

@AlexeyTsvetkov
Copy link

@deejay1 oh, I did not know about the autoconfigure processor. Still, the info above could be useful for those who only use the ConfigurationMetadataAnnotationProcessor (org.springframework.boot:spring-boot-configuration-processor artifact).

@m4rtin195
Copy link

I'd like to vote for some attention to this, it's already 3+ years since KAPT was deprecated. It's annoying to rely on this old, slow and error-prone processor.

@natalie-zamani
Copy link

Also curious when we might expect to see support for KSP.

@jeffawx
Copy link

jeffawx commented Apr 1, 2025

I don't even think I can get configuration processor + KAPT working perfectly, it works to some extent but when I started to put nested config class and default values, didn't see what I expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: pending-design-work Needs design work before any code can be developed theme: kotlin type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests