gradle / gradle

Adaptable, fast automation for all
https://gradle.org
Apache License 2.0
16.65k stars 4.66k forks source link

[configuration cache] file inputs are not recognized properly when using JGit / Grgit #25582

Open Vampire opened 1 year ago

Vampire commented 1 year ago

Expected Behavior

As the "dirty"-state is calculated, each and every file in the project should be a CC input. Of course this is not really helpful and should probably be done via ValueSource. But the point is, that CC does not consider all relevant files as inputs and thus produces wrong results.

Current Behavior

CC entry is reused while it shouldn't.

Context (optional)

This issue is very similar to the issue #25572 I reported in so far that input files are not considered properly. But I assume another root cause, so decided to report it as separate issue, as in that issue it seems to have to do with reading the file in a provider when the input property values are calculated and here I directly read the files at normal configuration time of the task.

Steps to Reproduce

Task :foo it is clean

BUILD SUCCESSFUL in 5s 1 actionable task: 1 executed $ echo a >foo $ ./gradlew foo

Task :foo it is dirty

BUILD SUCCESSFUL in 5s 1 actionable task: 1 executed $ git restore foo $ ./gradlew foo --configuration-cache Calculating task graph as no configuration cache is available for tasks: foo

Task :foo it is clean

0 problems were found storing the configuration cache.

See the complete report at file:///.../configuration-cache-report.html

BUILD SUCCESSFUL in 5s 1 actionable task: 1 executed Configuration cache entry stored. $ echo a >foo $ ./gradlew foo --configuration-cache Reusing configuration cache.

Task :foo it is clean

BUILD SUCCESSFUL in 5s 1 actionable task: 1 executed Configuration cache entry reused.


The last command should have not reused the configuration cache and should have printed "it is dirty".
But `foo` and `bar` are not considered input files.

### Report Data from CC Report

<details>
<summary>CC report</summary>
```json
{
  "diagnostics": [
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "value from custom source "
        },
        {
          "name": "JGitBootstrapper"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "environment variable "
        },
        {
          "name": "GIT_DIR"
        }
      ],
      "documentationLink": "https://docs.gradle.org/8.2/userguide/configuration_cache.html#config_cache:requirements:reading_sys_props_and_env_vars"
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "environment variable "
        },
        {
          "name": "GIT_OBJECT_DIRECTORY"
        }
      ],
      "documentationLink": "https://docs.gradle.org/8.2/userguide/configuration_cache.html#config_cache:requirements:reading_sys_props_and_env_vars"
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "environment variable "
        },
        {
          "name": "GIT_ALTERNATE_OBJECT_DIRECTORIES"
        }
      ],
      "documentationLink": "https://docs.gradle.org/8.2/userguide/configuration_cache.html#config_cache:requirements:reading_sys_props_and_env_vars"
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "environment variable "
        },
        {
          "name": "GIT_WORK_TREE"
        }
      ],
      "documentationLink": "https://docs.gradle.org/8.2/userguide/configuration_cache.html#config_cache:requirements:reading_sys_props_and_env_vars"
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "environment variable "
        },
        {
          "name": "GIT_INDEX_FILE"
        }
      ],
      "documentationLink": "https://docs.gradle.org/8.2/userguide/configuration_cache.html#config_cache:requirements:reading_sys_props_and_env_vars"
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "environment variable "
        },
        {
          "name": "GIT_CEILING_DIRECTORIES"
        }
      ],
      "documentationLink": "https://docs.gradle.org/8.2/userguide/configuration_cache.html#config_cache:requirements:reading_sys_props_and_env_vars"
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "system property "
        },
        {
          "name": "jgit.usecygpath"
        }
      ],
      "documentationLink": "https://docs.gradle.org/8.2/userguide/configuration_cache.html#config_cache:requirements:reading_sys_props_and_env_vars"
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file system entry "
        },
        {
          "name": ".git\\objects"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file system entry "
        },
        {
          "name": ".git\\refs"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file system entry "
        },
        {
          "name": ".git\\reftable"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file "
        },
        {
          "name": ".git\\HEAD"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file "
        },
        {
          "name": ".git\\config"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file system entry "
        },
        {
          "name": "."
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file system entry "
        },
        {
          "name": ".git\\.git"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file system entry "
        },
        {
          "name": ".gradle\\.git"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file system entry "
        },
        {
          "name": "gradle\\.git"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file system entry "
        },
        {
          "name": ".git\\packed-refs"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file "
        },
        {
          "name": ".git\\packed-refs"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file system entry "
        },
        {
          "name": ".git\\refs\\heads\\master"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file system entry "
        },
        {
          "name": ".git"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "directory content "
        },
        {
          "name": ".git\\objects\\pack"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file "
        },
        {
          "name": ".git\\objects\\pack\\pack-85e336e18bf708d9f362dbe2ad1bd49649c1d861.idx"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file system entry "
        },
        {
          "name": ".git\\shallow"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file system entry "
        },
        {
          "name": ".git\\index"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file "
        },
        {
          "name": ".git\\index"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file "
        },
        {
          "name": ".gitignore"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file system entry "
        },
        {
          "name": ".git\\info\\attributes"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "system property "
        },
        {
          "name": "org.eclipse.jgit.util.sha1.implementation"
        }
      ],
      "documentationLink": "https://docs.gradle.org/8.2/userguide/configuration_cache.html#config_cache:requirements:reading_sys_props_and_env_vars"
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file system entry "
        },
        {
          "name": ".git\\info\\exclude"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file "
        },
        {
          "name": ".git\\info\\exclude"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file "
        },
        {
          "name": "bar"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file "
        },
        {
          "name": "build.gradle.kts"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file system entry "
        },
        {
          "name": "gradle"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file system entry "
        },
        {
          "name": "gradle\\wrapper\\.git"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file system entry "
        },
        {
          "name": "gradle\\wrapper"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file "
        },
        {
          "name": "gradle\\wrapper\\gradle-wrapper.jar"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file "
        },
        {
          "name": "gradle\\wrapper\\gradle-wrapper.properties"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file "
        },
        {
          "name": "gradlew"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file "
        },
        {
          "name": "gradlew.bat"
        }
      ]
    },
    {
      "trace": [
        {
          "kind": "BuildLogic",
          "location": "build file 'build.gradle.kts'"
        }
      ],
      "input": [
        {
          "text": "file "
        },
        {
          "name": "settings.gradle.kts"
        }
      ]
    }
  ],
  "totalProblemCount": 0,
  "cacheAction": "storing",
  "requestedTasks": "foo",
  "documentationLink": "https://docs.gradle.org/8.2/userguide/configuration_cache.html"
}

Gradle version

8.2

jbartok commented 1 year ago

Thank you for providing a valid reproducer.

The issue is in the backlog of the relevant team and is prioritized by them.