The annotation processor reaches directly to the file system for the resources directory to load META-INF/additional-spring-configuration-metadata.json, and writes the file to the classes output directory. Because it's not a source file, it's not considered an input so changes to that file do not result in input fingerprints changing, which means that changes to that file result in tasks being UP-TO-DATE and build cache fingerprints do not change resulting in out of date metadata.

https://github.com/spring-projects/spring-boot/blob/47516b50c39bd6ea924a1f6720ce6d4a71088651/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/MetadataStore.java#L111-L137

I gather the dependency on a resource is is why the documentation recommends you wire processResources to compileJava, however the file should only be located from the source directories for compilation:

https://docs.spring.io/spring-boot/docs/current/reference/html/configuration-metadata.html#configuration-metadata.annotation-processor.configuring

To reproduce, in a project with an additional-spring-configuration-metadata.json file:

  1. Run compileJava
  2. Modify the json file
  3. Re-run compileJava and note that the task is UP-TO-DATE

Comment From: wilkinsona

Thanks for the report. Unfortunately, I cannot reproduce the behaviour that you have described with Spring Boot 2.5 using either Gradle 6.9 or 7.1.

Here's a build after changing the additional metadata:

 ./gradlew compileJava --info
Initialized native services in: /Users/awilkinson/.gradle/native
The client will now receive all logging from the daemon (pid: 80049). The daemon log file: /Users/awilkinson/.gradle/daemon/6.9/daemon-80049.out.log
Starting 4th build in daemon [uptime: 59.759 secs, performance: 99%, non-heap usage: 24% of 256 MiB]
Using 8 worker leases.
Watching the file system is disabled
Starting Build
Settings evaluated using settings file '/Users/awilkinson/dev/temp/gh-27093/settings.gradle'.
Projects loaded. Root project using build file '/Users/awilkinson/dev/temp/gh-27093/build.gradle'.
Included projects: [root project 'gh-27093']

> Configure project :
Evaluating root project 'gh-27093' using build file '/Users/awilkinson/dev/temp/gh-27093/build.gradle'.
All projects evaluated.
Selected primary task 'compileJava' from project :
Tasks to be executed: [task ':processResources', task ':compileJava']
Tasks that were excluded: []
:processResources (Thread[Execution worker for ':',5,main]) started.

> Task :processResources
Caching disabled for task ':processResources' because:
  Build cache is disabled
Task ':processResources' is not up-to-date because:
  Input property 'rootSpec$1' file /Users/awilkinson/dev/temp/gh-27093/src/main/resources/META-INF/additional-spring-configuration-metadata.json has changed.
:processResources (Thread[Execution worker for ':',5,main]) completed. Took 0.011 secs.
:compileJava (Thread[Execution worker for ':',5,main]) started.

> Task :compileJava
Caching disabled for task ':compileJava' because:
  Build cache is disabled
Task ':compileJava' is not up-to-date because:
  Input property '$1' file /Users/awilkinson/dev/temp/gh-27093/build/resources/main/META-INF/additional-spring-configuration-metadata.json has changed.
The input changes require a full rebuild for incremental task ':compileJava'.
Full recompilation is required because no incremental change information is available. This is usually caused by clean builds or changing compiler arguments.
Compiling with JDK Java compiler API.
Created classpath snapshot for incremental compilation in 0.0 secs.
:compileJava (Thread[Execution worker for ':',5,main]) completed. Took 0.068 secs.

BUILD SUCCESSFUL in 667ms
2 actionable tasks: 2 executed

Building again without any changes reports that the task is UP-TO-DATE:

 ./gradlew compileJava --info
Initialized native services in: /Users/awilkinson/.gradle/native
The client will now receive all logging from the daemon (pid: 80049). The daemon log file: /Users/awilkinson/.gradle/daemon/6.9/daemon-80049.out.log
Starting 5th build in daemon [uptime: 3 mins 17.132 secs, performance: 99%, non-heap usage: 25% of 256 MiB]
Using 8 worker leases.
Watching the file system is disabled
Starting Build
Settings evaluated using settings file '/Users/awilkinson/dev/temp/gh-27093/settings.gradle'.
Projects loaded. Root project using build file '/Users/awilkinson/dev/temp/gh-27093/build.gradle'.
Included projects: [root project 'gh-27093']

> Configure project :
Evaluating root project 'gh-27093' using build file '/Users/awilkinson/dev/temp/gh-27093/build.gradle'.
All projects evaluated.
Selected primary task 'compileJava' from project :
Tasks to be executed: [task ':processResources', task ':compileJava']
Tasks that were excluded: []
:processResources (Thread[Execution worker for ':',5,main]) started.

> Task :processResources UP-TO-DATE
Caching disabled for task ':processResources' because:
  Build cache is disabled
Skipping task ':processResources' as it is up-to-date.
:processResources (Thread[Execution worker for ':',5,main]) completed. Took 0.004 secs.
:compileJava (Thread[Execution worker for ':',5,main]) started.

> Task :compileJava UP-TO-DATE
Caching disabled for task ':compileJava' because:
  Build cache is disabled
Skipping task ':compileJava' as it is up-to-date.
:compileJava (Thread[Execution worker for ':',5,main]) completed. Took 0.014 secs.

BUILD SUCCESSFUL in 656ms
2 actionable tasks: 2 up-to-date

Changing the additional metadata and running the build again results in compileJava being executed:

 ./gradlew compileJava --info
Initialized native services in: /Users/awilkinson/.gradle/native
The client will now receive all logging from the daemon (pid: 80049). The daemon log file: /Users/awilkinson/.gradle/daemon/6.9/daemon-80049.out.log
Starting 6th build in daemon [uptime: 3 mins 57.687 secs, performance: 99%, non-heap usage: 25% of 256 MiB]
Using 8 worker leases.
Watching the file system is disabled
Starting Build
Settings evaluated using settings file '/Users/awilkinson/dev/temp/gh-27093/settings.gradle'.
Projects loaded. Root project using build file '/Users/awilkinson/dev/temp/gh-27093/build.gradle'.
Included projects: [root project 'gh-27093']

> Configure project :
Evaluating root project 'gh-27093' using build file '/Users/awilkinson/dev/temp/gh-27093/build.gradle'.
All projects evaluated.
Selected primary task 'compileJava' from project :
Tasks to be executed: [task ':processResources', task ':compileJava']
Tasks that were excluded: []
:processResources (Thread[Execution worker for ':',5,main]) started.

> Task :processResources
Caching disabled for task ':processResources' because:
  Build cache is disabled
Task ':processResources' is not up-to-date because:
  Input property 'rootSpec$1' file /Users/awilkinson/dev/temp/gh-27093/src/main/resources/META-INF/additional-spring-configuration-metadata.json has changed.
:processResources (Thread[Execution worker for ':',5,main]) completed. Took 0.005 secs.
:compileJava (Thread[Execution worker for ':',5,main]) started.

> Task :compileJava
Caching disabled for task ':compileJava' because:
  Build cache is disabled
Task ':compileJava' is not up-to-date because:
  Input property '$1' file /Users/awilkinson/dev/temp/gh-27093/build/resources/main/META-INF/additional-spring-configuration-metadata.json has changed.
The input changes require a full rebuild for incremental task ':compileJava'.
Full recompilation is required because no incremental change information is available. This is usually caused by clean builds or changing compiler arguments.
Compiling with JDK Java compiler API.
Created classpath snapshot for incremental compilation in 0.0 secs.
:compileJava (Thread[Execution worker for ':',5,main]) completed. Took 0.058 secs.

BUILD SUCCESSFUL in 626ms
2 actionable tasks: 2 executed

I guess there's something different about your setup. If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

Comment From: DanielThomas

Thanks @wilkinsona - this project is Spring Boot library so doesn't have any additional plugins applied. That's doesn't look like a default input to the task, is the Spring Boot plugin adding this additional input?

  Input property '$1' file /Users/awilkinson/dev/temp/gh-27093/build/resources/main/META-INF/additional-spring-configuration-metadata.json has changed.

Comment From: wilkinsona

No, I declared that input manually as described in the Spring Boot documentation that you linked to above and in Gradle’s own documentation:

If you are using an annotation processor that reads resources (e.g. a configuration file), you need to declare those resources as an input of the compile task.

Given the above, this sounds like some missing configuration in your build. If things don’t work as expected with the required input declaration, please provide a minimal sample and we can re-open and take another look.

Comment From: DanielThomas

Oh, I totally misread that part of the documentation, sorry for the false alarm. I'll let the Spring Boot Netflix folks know to look out for this, thanks again!