Caching is always disabled when using AWS CodeBuild

I’m trying to use an EFS volume on CodeBuild to cache compiled classes between builds, using Gradle 6.

From looking at the debug log output below, it seems that Gradle is disabling caching for two reasons:

  1. Something about forking… does forking disable caching?
  2. It says the output property has been removed. What does that mean? This is showing the wrong path (/codebuild/output/src133641298/src/git-codecommit.us-east-1.amazonaws.com/v1/repos/HamsterBall/out/production/ProscAmazonSimpleDB), the correct path (/SharedVolume/MirrorSyncBuild/out/production/ProscAmazonSimpleDB) is just a few lines lower in the log, so I know I’m setting it correctly.
2022/09/22 21:59:50 null null
INFO: 2022-09-22T22:00:57.955+0000 [INFO] [org.gradle.internal.execution.steps.ResolveCachingStateStep] Caching disabled for task ':ProscAmazonSimpleDB:compileJava' because:
  'Forking compiler via ForkOptions.executable' satisfied
2022-09-22T22:00:57.955+0000 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Completing Build operation 'Snapshot task inputs for :ProscAmazonSimpleDB:compileJava'
2022-09-22T22:00:57.955+0000 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Snapshot task inputs for :ProscAmazonSimpleDB:compileJava' completed
2022-09-22T22:00:57.956+0000 [DEBUG] [org.gradle.internal.execution.steps.SkipUpToDateStep] Determining if task ':ProscAmazonSimpleDB:compileJava' is up-to-date
2022-09-22T22:00:57.956+0000 [INFO] [org.gradle.internal.execution.steps.SkipUpToDateStep] Task ':ProscAmazonSimpleDB:compileJava' is not up-to-date because:
  Output property 'destinationDirectory' file /codebuild/output/src133641298/src/git-codecommit.us-east-1.amazonaws.com/v1/repos/HamsterBall/out/production/ProscAmazonSimpleDB has been removed.
  Output property 'destinationDirectory' file /codebuild/output/src133641298/src/git-codecommit.us-east-1.amazonaws.com/v1/repos/HamsterBall/out/production/ProscAmazonSimpleDB/com has been removed.
  Output property 'destinationDirectory' file /codebuild/output/src133641298/src/git-codecommit.us-east-1.amazonaws.com/v1/repos/HamsterBall/out/production/ProscAmazonSimpleDB/com/prosc has been removed.
2022-09-22T22:00:57.956+0000 [DEBUG] [org.gradle.internal.execution.steps.CreateOutputsStep] Ensuring directory exists for property destinationDirectory at /SharedVolume/MirrorSyncBuild/out/production/ProscAmazonSimpleDB
2022-09-22T22:00:57.959+0000 [DEBUG] [org.gradle.internal.execution.steps.CreateOutputsStep] Ensuring directory exists for property options.generatedSourceOutputDirectory at /SharedVolume/MirrorSyncBuild/out/gradle/ProscAmazonSimpleDB/generated/sources/annotationProcessor/java/main
2022-09-22T22:00:57.962+0000 [DEBUG] [org.gradle.internal.execution.steps.CreateOutputsStep] Ensuring directory exists for property options.headerOutputDirectory at /SharedVolume/MirrorSyncBuild/out/gradle/ProscAmazonSimpleDB/generated/sources/headers/java/main
2022-09-22T22:00:57.976+0000 [INFO] [org.gradle.internal.execution.steps.ResolveInputChangesStep] The input changes require a full rebuild for incremental task ':ProscAmazonSimpleDB:compileJava'.

Something about forking… does forking disable caching?

Forking per-se does not.
But forking using ForkOptions.executable does, just as the log line tells.
I guess this is because then the executable used is unknown and thus Gradle cannot know whether it is really safe to cache the result or not and thus caching is disabled to be on the safe side.

It says the output property has been removed. What does that mean?

It does not say the property has been removed, it says the files X, Y, and Z from that output property are deleted on disk.

This is showing the wrong path (/codebuild/output/src133641298/src/git-codecommit.us-east-1.amazonaws.com/v1/repos/HamsterBall/out/production/ProscAmazonSimpleDB), the correct path (/SharedVolume/MirrorSyncBuild/out/production/ProscAmazonSimpleDB) is just a few lines lower in the log, so I know I’m setting it correctly.

Well, obviously you are not setting it correctly.
Maybe you set it for example in the exeuction phase of the task and thus when doing the up-to-date check it is still on the old value or similar.
Hard to guess without seeing your build script.