Skip to content

Gradle cache doesn't work when the same project is cloned to different location and graphqlCodegen task is executed #1456

Open
@itsnagaraj

Description

@itsnagaraj

Issue Description

Gradle cache doesn't work when the same project is cloned to different location as the file inputs declared using InputFile are not declared with @PathSensitive(PathSensitivity.RELATIVE).

Steps to Reproduce

In our project we use graphqlQueryIntrospectionResultPath to generate java classes. Every time when the developers creates new feature branch, GraphQL classes are regenerated even when introspection result file hasn't changed. On debugging the cache computation noticed that most of the input files are not marked with relative path sensitivity.

when built from original cloned folder the cache key is computed as below

Appending input file fingerprints for 'graphqlQueryIntrospectionResultPath' to build cache key: 2dd0b667193a08224bb85235c5be67b2 - ABSOLUTE_PATH{/Users/xxxxx/Projects/service-a/graphql-client/src/main/resources/graphql/introspection-result.json='/Users/xxxxx/Projects/service-a/graphql-client//src/main/resources/graphql/introspection-result.json' / 71e1b7cce6d99cbeefb868790c467850}

the same code built from another folder result in different cache key

Appending input file fingerprints for 'graphqlQueryIntrospectionResultPath' to build cache key: 87d2d3337b15ca3b875538b6b9a17ab1 - ABSOLUTE_PATH{/Users/xxxxxyyy/Projects/service-a/graphql-client//src/main/resources/graphql/introspection-result.json='/Users/xxxxxyyy/Projects/service-a/graphql-client//src/main/resources/graphql/introspection-result.json' / 71e1b7cce6d99cbeefb868790c467850}

Expected Result

If the introspection result hasn't changed the classes should be used from the cache rather than being generated

Actual Result

Classes are regenerated every time the source code is cloned into different folder. This adds additional time to builds on CI server as each feature branch are cloned to different folders.

Your Environment and Setup

  • graphql-java-codegen version: 5.8.0
  • Build tool: E.g.: Gradle
  • Mapping Config: E.g.:
graphqlCodegen {
    afterEvaluate {
        def introspectionFilePath = project.findProperty("graphqlIntrospectionResultPath") ?: "${projectDir}/src/main/resources/graphql/introspection-result.json"
        def generatedClassesPath = "$buildDir/generated/graphql/src/main/java"

        outputs.cacheIf {true}

        graphqlQueryIntrospectionResultPath = introspectionFilePath
        outputDir = new File(generatedClassesPath)
        packageName = project.findProperty("packageNameForGeneratedTypes")
        generateClient = true
        generateModelsForRootTypes = true
        generateBuilder = true
        generateEqualsAndHashCode = true
        generateToString = true
        generateParameterizedFieldsResolvers = false
        customTypesMapping = project.findProperty("mappedCustomTypes") ?: [:]
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions