Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

artifactsReport granular cache inputs #1219

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

seregamorph
Copy link
Contributor

@seregamorph seregamorph commented Jul 8, 2024

Problem statement

artifactsReportX tasks (ArtifactsReportTask) declare too "sensitive" file task inputs (absolute file path + full file contents). But the task output does not depend on file content itself, only on resolved dependency tree. As a result, the caching hit rate for these tasks is quite low.

Proposed solution

The problematic task input:

/**
 * This is the "official" input for wiring task dependencies correctly, but is otherwise
 * unused. This needs to use [InputFiles] and [PathSensitivity.ABSOLUTE] because the path to the
 * jars really does matter here. Using [Classpath] is an error, as it looks only at content and
 * not name or path, and we really do need to know the actual path to the artifact, even if its
 * contents haven't changed.
 */
@PathSensitive(PathSensitivity.ABSOLUTE)
@InputFiles
fun getClasspathArtifactFiles(): FileCollection = artifacts.artifactFiles

should be replaced with absolute file paths only:

@Input
fun getClasspathArtifactFilePaths(): Set<String> = artifacts.artifactFiles.mapToSet { it.path }

From the debugger, sample file inputs (Set of String values):

0 = "/Users/morph/Projects/demo-gradle-included-issue/module-contracts/build/libs/module-contracts.jar"
1 = "/Users/morph/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-lang3/3.14.0/1ed471194b02f2c6cb734a0cd6f6f107c673afae/commons-lang3-3.14.0.jar"

FYI: sample artifactsReportMain task output looks like:

[
  {
    "coordinates": {
      "type": "included_build",
      "identifier": "isolated-build-1:module-contracts",
      "resolvedProject": {
        "identifier": ":module-contracts",
        "gradleVariantIdentification": {
          "capabilities": [
            "isolated-build-1:module-contracts"
          ],
          "attributes": {}
        },
        "buildPath": ":"
      },
      "gradleVariantIdentification": {
        "capabilities": [
          "isolated-build-1:module-contracts"
        ],
        "attributes": {}
      }
    },
    "file": "/Users/morph/Projects/demo-gradle-included-issue/module-contracts/build/libs/module-contracts.jar"
  },

as you can see - does not depend on jar content, only on dependency resolution.

Testing

The functional test is not attached. Let me know WDYT about this change and if there is a green light, I can try to provide a test. The problem here is that the test should assert the caching result. It is possible, but requires extended test setup.

@seregamorph seregamorph marked this pull request as draft July 8, 2024 18:37
@seregamorph
Copy link
Contributor Author

The builds fails on functionalTests, but only for android. It seems that file iteration has side effect. I need some time to investigate it, but still curious about the idea in general.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant