Cannot determine why Gradle downloads compileClasspath dependencies at configuration phase

Viewed 68

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 not 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"
}
1 Answers

Disclaimer: I never worked with Gradle's build cache feature so far. This answer is solely based on documentation and experience, so please take my answer with a grain of salt.

Gradle keeps track of the inputs and outputs of a task to avoid executing them again if nothing changed. This is indicated by Gradle's UP-TO-DATE output. Amongst others, the inputs of the compileJava task are the project's source files and its dependencies. Task outputs are cached like this:

Since a task describes all of its inputs and outputs, Gradle can compute a build cache key that uniquely defines the task’s outputs based on its inputs. (Cacheable Tasks)

(Emphasis is mine)

This means: The build cache key is comprised of a task's inputs and since dependencies, their source and hashes are part of compileJava's inputs, they must be resolved first.

Related