Cannot determine why Gradle downloads compileClasspath dependencies at configuration phase

From reading how to improve Gradle build performance, I understand that dependencies should not be downloaded in configuration phase.

I am using remote build cache always running builds from scratch in empty Docker container.

My build always downloads all dependencies for :compileClasspath even if :compileJava task is taken from build cache.

I was under impression that Gradle would now download dependencies if :compileJava is already in cache and there is no need for its execution.

Here is sample build.gradle

plugins {
    id 'java'
}

repositories {
    mavenCentral()
}

dependencies {
    def springBootVersion = '2.4.2'

    implementation "org.springframework.boot:spring-boot-starter:$springBootVersion"
}

Having very little experience with the build cache, here’s my guess; the compile classpath is an input to the compileJava task, so the dependencies are part of the task’s cache key and therefore need to be downloaded in order to perform the key calculation.

the dependencies are part of the task’s cache key and therefore need to be downloaded in order to perform the key calculation

Yep, that makes sense to me also

Thanks for your answers. My thinking was that it should not download jar files in order to calculate if dependencies changed or not, there are checksums for that.

The inputs to the compileJava task are (possibly not an exhaustive list)

  1. The java sources
  2. The compile classpath (the jars)

Gradle will create a hash of these to use as a cache key

What checksums? I assume that “from scratch in empty Docker container” means there is no state from previous builds that Gradle can re-use.

Yes, I was referring to maven metadata, Java plugin could download only metadata instead of jar files and calculate dependencies input change based on those.