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

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

Open
itsnagaraj opened this issue Feb 5, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@itsnagaraj
Copy link

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") ?: [:]
    }
}
@itsnagaraj itsnagaraj added the bug Something isn't working label Feb 5, 2024
@itsnagaraj itsnagaraj changed the title [Short Description] Gradle cache doesn't work when the same project is cloned to different location and graphqlCodegen task is executed Feb 6, 2024
@MartyWind
Copy link

I just ran into this myself and it is even worse:
This bug results in the whole gradle build being unable to utilize the gradle build cache, because the @Generated annotation contains a timestamp per default. That makes the builds not reproducible as all following cache keys change.

I worked around this by setting addGeneratedAnnotation = false so the output is identical and subsequent gradle task can compute the same cache key.

But this should be prevented per default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants