Info

Gradle's incremental build doesn't work when using annotations with source retention (@Override, @Generated, Lombok's @Data) and spring-boot-configuration-processor (removing it solves the problem).

Spring Boot version: 2.4.0-M3 Example: https://github.com/ve2m/spring-boot-gradle-incremental-problem

Reproduction steps

  1. git clone git@github.com:ve2m/spring-boot-gradle-incremental-problem.git
  2. ./gradlew compileJava --info
  3. Make some changes to Entity
  4. ./gradlew compileJava --info, note that there is a message saying:

    Full recompilation is required because @Data has source retention.

  5. Comment out annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' in build.gradle

  6. Repeat steps 2-4 and note that incremental build works.

Comment From: wilkinsona

Thanks for the sample.

This is due to the annotation processor stating that it supports all types of annotations. The processor used to only support @ConfigurationProperties but this was changed in https://github.com/spring-projects/spring-boot/commit/7e5bb9697c0c0b64e05e6d77810c74477873c903 to fix #1830.

We do now have some usage of @ConfigurationProperties in spring-boot so the problem described in #1830 wouldn't occur if we reverted 7e5bb96. However, the usage is related to JTA and may well be removed in the not-too-distant future so a revert of 7e5bb96 would fix this problem while reintroducing another one.

I suspect it's quite unusual for a project to have additional configuration property metadata and no usage of @ConfigurationProperties. Given the warning in the javadoc against using * and the problem that it causes with Gradle's incremental compilation, it feels like the problems caused by the fix are broader than the problem that it's solving and that we'd be better finding a solution for #1830 that doesn't affect everyone using spring-boot-configuration-processor.

One option would be to require the use of an annotation processor argument to opt in to supporting all annotation types. This argument could then be set by projects that have an additional metadata file but no usage of @ConfigurationProperties. Another would be to go back to the original fix for #1830 which removed the annotation processor and renamed additional-spring-configuration-metadata.json to spring-configuration-metadata.json.

Comment From: philwebb

We'll list @ConfigurationProperties and @Configuration.

Comment From: snicoll

We also generate metadata for org.springframework.boot.actuate.endpoint.annotation.Endpoint so that one should be declared as well.

Comment From: wilkinsona

@Endpoint has been added a supported annotation in c82581171dbb04c1803e7257413babbfa479b70a.