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

Build fails after schema file rename when Gradle configuration cache enabled #5455

Closed
varahash opened this issue Dec 11, 2023 · 1 comment · Fixed by #5580
Closed

Build fails after schema file rename when Gradle configuration cache enabled #5455

varahash opened this issue Dec 11, 2023 · 1 comment · Fixed by #5580

Comments

@varahash
Copy link

Version

3.8.2 and 4.0.0-beta.3

Summary

Currently build fails if you rename schema file and configuration cache was enabled. Take a look at the steps to reproduce issue below.

My current workaround
I have little bit investigated this and it seems the problem in the following code (schema files searched in a non-compatible way with configuration cache)

return graphqlSourceDirectorySet.srcDirs.flatMap { srcDir ->
srcDir.walkTopDown().filter {
it.extension in listOf("json", "sdl", "graphqls")
&& !it.name.startsWith("used") // Avoid detecting the used coordinates as a schema
}.toList()
}.toSet()

To workaround this, I set Service.schemaFiles directly instead of relying on default behavior.

apollo {
    service("main") {
        srcDir("src/main/graphql")
        schemaFiles.setFrom(
            fileTree("src/main/graphql") {
                include("**/*.graphqls")
            }
        )
    }
}

PS: since in my project I have multiple schema files, I cannot use just Service.schemaFile for single file

Steps to reproduce the behavior

Steps

  1. Create simple my_lib module and use default configuration for Apollo plugin. Place GQL schema file into main sources: /Users/user/projects/sample/my_lib/src/main/graphql/schema.graphqls
  2. Build module with configuration cache enabled ./gradlew :my_lib:assembleDebug --configuration-cache
  3. Rename schema.graphqls to schema2.graphqls
  4. Build module again with configuration cache enabled ./gradlew :my_lib:assembleDebug --configuration-cache

Actual result
The second build fails with error

> Task :my_lib:generateMainApolloSources FAILED
Execution failed for task ':my_lib:generateMainApolloSources'.
> java.io.FileNotFoundException: /Users/user/projects/sample/my_lib/src/main/graphql/schema.graphqls (No such file or directory)

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
BUILD FAILED in 307ms
122 actionable tasks: 6 executed, 116 up-to-date
Configuration cache entry reused.

Expected result
Build must success

Logs

No response

@martinbonnin
Copy link
Contributor

Thanks for opening this 🙏

Linking #5221 as I think they share the same root cause.

martinbonnin added a commit that referenced this issue Jan 29, 2024
martinbonnin added a commit that referenced this issue Jan 29, 2024
martinbonnin added a commit that referenced this issue Feb 5, 2024
…iles (#5580)

* add a test for #5455

* Fix configuration cache and schema file auto detection

Closes #5455
Closes #5221

* add a test for #5221
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants