There is an inconsistent support in GeneratedContext at the moment. Source code benefits from GeneratedClasses with several helper to generate unique class names based on feature or feature component.
Resources, on the other hand, have no such link. At the moment we need to go through the GeneratedFiles contract which only offers bare bone utilities to add a file whose name is provided by the caller.
Two use cases that this would help with:
- If a resource needs to be generated based on
Class(like a metadata file, Spring Data does this) thenGeneratedResourcescould take care of the naming (+ location) based on the type and the name of the feature. - Resources are more likely to be idempotent. If a resource is generated based on the type, the type will not change based on the state of the
ApplicationContext. This is again the case for Spring Data and we should offer a way to gently ignore if the file has always been generated.
See also https://github.com/spring-projects/spring-framework/issues/35855 for an example of a file with a unique name that will cause such problem.