Limit supported annotations to @ConfigurationProperties and @Configuration

Previously, the configuration property annotation processor declared
that it supported all annotation types. This hurt performance and
prevented incremental builds with Gradle when compiling source code
containing source-retention annotations.

This commit updates its supported annotation types to be only
`@ConfigurationProperties` and `@Configuration`. The latter is declared
to allow binding third-party classes returned from a `@Bean` method.

Fixes gh-23580
This commit is contained in:
Andy Wilkinson 2020-10-06 14:54:24 +01:00
parent f44889b992
commit 1924aad07c
2 changed files with 9 additions and 1 deletions

View File

@ -59,7 +59,8 @@ import org.springframework.boot.configurationprocessor.metadata.ItemMetadata;
* @author Jonas Keßler
* @since 1.2.0
*/
@SupportedAnnotationTypes({ "*" })
@SupportedAnnotationTypes({ ConfigurationMetadataAnnotationProcessor.CONFIGURATION_PROPERTIES_ANNOTATION,
"org.springframework.context.annotation.Configuration" })
public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor {
static final String ADDITIONAL_METADATA_LOCATIONS_OPTION = "org.springframework.boot.configurationprocessor.additionalMetadataLocations";

View File

@ -68,6 +68,13 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
*/
class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGenerationTests {
@Test
void supportedAnnotations() {
assertThat(new ConfigurationMetadataAnnotationProcessor().getSupportedAnnotationTypes())
.containsExactlyInAnyOrder("org.springframework.boot.context.properties.ConfigurationProperties",
"org.springframework.context.annotation.Configuration");
}
@Test
void notAnnotated() {
ConfigurationMetadata metadata = compile(NotAnnotated.class);