Assuming a BeanFactoryInitializationAotProcessor would like to register a resource that's not dependent on the ConfigurableListableBeanFactory handed into the method but globally applicable. It would return a BeanFactoryInitializationAotContribution that'd do something like this with the GenerationContext provided:

context.getGeneratedFiles().addResourceFile("someLocation", "someContent");

This fails for a subsequent run of the AOT process if the build hasn't cleaned out someLocation beforehand, as the resource creation rejects overwriting files by default. To reliably always create or replace the file to be created, one has to resort to this:

context.getGeneratedFiles().handleFile(Kind.RESOURCE, "someLocation", it -> {

    var resource = new ByteArrayResource("someContent".getBytes(StandardCharsets.UTF_8));

    if (it.exists()) {
        it.override(resource);
    } else {
        it.create(resource);
    }
});

This is pretty involved compared to the simple call to ….addResourceFile(…). I wonder if it makes sense to add method overloads that allow triggering the always-override behavior. Or, alternatively, flip the default to allow the override and rely on users with more advanced needs to simply use the already existing API that gives them more control over the file creation.

Related tickets

  • spring-projects/spring-modulith#1457