Same cache hashes but cache is not used

Hi everyone,

The --build-cache is working for unit tests but not for integration tests. I’ve ran one test several times and compared the cache hashes by using a diff tool, all the cache hashes are the same on every attempt.

The command I am running:

./gradlew clean -Dorg.gradle.caching.debug=true \
  --no-daemon \
  integrationTest \
  --build-cache --tests "com.platform.smoke.ColorTest"

The result I am getting:

16 actionable tasks: 11 executed, 4 from cache, 1 up-to-date
> Task :backend-api:integrationTest
...
Appending input file fingerprints for 'testFrameworkProperty.options.suiteXmlFiles' to build cache key: 5fd1e7396e8de4cb5c23dc6aadd7787a - IGNORED_PATH{EMPTY}
Appending output property name to build cache key: binaryResultsDirectory
Appending output property name to build cache key: jvmArgumentProviders.jacocoAgent$0.jacoco.destinationFile
Appending output property name to build cache key: options.outputDirectory
Appending output property name to build cache key: reports.enabledReports.html.outputLocation
Appending output property name to build cache key: reports.enabledReports.junitXml.outputLocation
Appending output property name to build cache key: testFrameworkProperty.options.outputDirectory
Build cache key for task ':backend-api:integrationTest' is aede07664fdd30efd89605cb823d8b21

It seems to build the cache properly - could someone please help me understand why the consequent tests are not picking up the cache?

Thank you so much in advance <3

Do you maybe get more info with --info why the task is run / cache not reused?
Can you provide a build scan?

@Vampire
I’ve ran in --debug and obtained a bit more of info:

2022-11-16T16:21:50.287+0100 [WARN] [org.gradle.internal.execution.steps.ResolveCachingStateStep] Build cache key for task ':backend-api:integrationTest' is 154ec4e746e42ce2572c40a437b570d8
2022-11-16T16:21:50.289+0100 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationRunner] Build operation 'Snapshot task inputs for :backend-api:integrationTest' completed
2022-11-16T16:21:50.289+0100 [DEBUG] [org.gradle.internal.execution.steps.SkipUpToDateStep] Determining if task ':backend-api:integrationTest' is up-to-date
2022-11-16T16:21:50.289+0100 [INFO] [org.gradle.internal.execution.steps.SkipUpToDateStep] Task ':backend-api:integrationTest' is not up-to-date because:
  Task.upToDateWhen is false.
2022-11-16T16:21:50.290+0100 [DEBUG] [org.gradle.internal.execution.steps.BuildCacheStep] Did not find cache entry for task ':backend-api:integrationTest' with cache key 154ec4e746e42ce2572c40a437b570d8, executing instead

and when the test ends:

2022-11-16T16:30:38.608+0100 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationRunner] Build operation 'Pack build cache entry 154ec4e746e42ce2572c40a437b570d8' started
2022-11-16T16:30:38.860+0100 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationRunner] Completing Build operation 'Pack build cache entry 154ec4e746e42ce2572c40a437b570d8'
2022-11-16T16:30:38.607+0100 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger]
2022-11-16T16:30:38.607+0100 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger] > Task :backend-api:integrationTest
2022-11-16T16:30:38.860+0100 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationRunner] Build operation 'Pack build cache entry 154ec4e746e42ce2572c40a437b570d8' completed
2022-11-16T16:30:38.867+0100 [INFO] [org.gradle.internal.execution.steps.BuildCacheStep] Stored cache entry for task ':backend-api:integrationTest' with cache key 154ec4e746e42ce2572c40a437b570d8

What I find weird is this:

Did not find cache entry for task ':backend-api:integrationTest' with cache key 154ec4e746e42ce2572c40a437b570d8

as I can see that this indeed exists in my machine:

~/.gradle/caches/build-cache-1/154ec4e746e42ce2572c40a437b570d8

and the gradle.build file:

sourceSets {
    integrationTest {
        java {
            compileClasspath += main.output + test.output
            runtimeClasspath += main.output + test.output
            srcDir file('src/integration-test/java')
        }
        resources.srcDir file('src/integration-test/resources')
    }
}

configurations {
    integrationTestImplementation.extendsFrom testImplementation
    integrationTestRuntime.extendsFrom testRuntime
}

task integrationTest(type: Test) {
    useTestNG()
    testClassesDirs = sourceSets.integrationTest.output.classesDirs
    testLogging.showStandardStreams = true
    classpath = sourceSets.integrationTest.runtimeClasspath
    jvmArgs '-Xmx8G'
    outputs.upToDateWhen { false }
}

Only now noticed the issue!!

 outputs.upToDateWhen { false }

So the task is always re-run. Removing that made the cache work just fine.

@Vampire thank you for your suggestion to use --info : ))