-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Hi folks,
we are using initializr to create larger enterprise-wide setup and are extending it in several directions.
One of the important things that we observed was the inability to exclude ProjectGenerationConfiguration from being processed. This is a little problematic, because once on the classpath, they are loaded via Spring SPI Loader. And since the initializr-spring module provides many useful things, we wanted to be able to disable configuration explicitly.
Do you think this is a good idea?
We implemented the following solution and would like to contribute it back, if you think it makes sense. In general, we managed to subclass the ProjectGenerator and overwrite the method getCandidateProjectGenerationConfigurations. In our implementation, we filter the detected candidates by comparing them with another list, beefore returning:
protected List<String> getCandidateProjectGenerationConfigurations(ProjectDescription description) {
var excludedNames = SpringFactoriesLoader.loadFactoryNames(
ExcludedProjectGenerationConfiguration.class, getClass().getClassLoader()
);
log.trace("Found excluded configurations: {}", String.join(", ", excludedNames));
return super.getCandidateProjectGenerationConfigurations(description)
.stream()
.filter(candidate -> !excludedNames.contains(candidate))
.toList();
}By doing so, I can specify in spring.factories:
io.spring.initializr.generator.project.ExcludedProjectGenerationConfiguration=\
io.spring.initializr.generator.spring.code.java.JavaProjectGenerationConfiguration, \
io.spring.initializr.generator.spring.configuration.ApplicationConfigurationProjectGenerationConfiguration
and exclude those two generation configurations, ExcludedProjectGenerationConfiguration being just a marker annotation and not effectively doing anything else.
In general, by providing this small change, we would benefit of throwing away a lot of code related to replacement of the ProjectGeneratorInvokerand the surronding ecosystem (because it is not very easy to replace the ProjectGenerator creation / invocation).
Are you interested?
We would love to contribute back.