feat: add optional and auto-detected @NullMarked annotation for generated classes - #4
feat: add optional and auto-detected @NullMarked annotation for generated classes#4kistlers wants to merge 1 commit into
Conversation
|
Hey @kistlers ! Thanks a lot for your efforts to improve the library. I am currently on vacation, so I won‘t be able to take a closer look until after my return.
So if I had to implement this feature, I would simply add configuration options to add the nullability annotations of my choice. Thanks again for your contribution! |
|
The reason for jspecify is simple. It is the new standard for nullability, supported by everyone, in a consortium led by Google. See https://jspecify.dev/docs/whether/ and https://jspecify.dev/about/ In that case however, I am not adding NotNull/Nullable annotations, but rather @NullMarked, which is another annotation https://jspecify.dev/docs/user-guide/#nullmarked that tells a static analyser that this class or package treats types as defaulf NonNull (as opposed to the Java default). As an example, Spring Boot 4 is fully NullMarked with jspecify (NonNull as the default) and kotlin 1.82 and newer understands jspecify annotations as-well :) Due to how quickly this is "spreading" I would argue that the detection is preferable, so that everyone that upgrades to the new version will alrrady have the generated classes annotated, as adding NullMarked has no downsides for everyone, including those that do not enforce every package to be null-marked. But it is very helpful for everyone that enforces it :) |
|
I see. Excuse my ignorance, we are switching to Spring Boot 4 sometime in the next two or three months 😜 I will take a closer look soon, I promise! |
|
All good :D Unrelated: I have opened another issue in the service accompanying this plugin, since I already got your attention :D |
Closes #3
Description
This PR adds support for annotating generated Java classes with
@NullMarked(org.jspecify.annotations.NullMarked).Features
org.jspecify:jspecifyis present in the project's dependencies or artifacts. If present,@NullMarkedis automatically imported and added to generated classes. If not present, it is safely omitted (no extra dependencies required).<addNullMarked>configuration parameter (true/false) to explicitly force or disable annotation generation.Changes
isJSpecifyPresent()andisNullMarked()helper methods inGenerateServiceMojo.GenerateServiceMojoTest.README.mddocumentation.