Skip to content

Make generateJava cacheable and relocatable - #967

Merged
iuliiasobolevska merged 1 commit into
masterfrom
perf/cacheable-generate-java
Sep 24, 2026
Merged

iuliiasobolevska merged 1 commit into
masterfrom
perf/cacheable-generate-java

Conversation

@iuliiasobolevska

@iuliiasobolevska iuliiasobolevska commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • make GenerateJavaTask cacheable with relative schema inputs and lazy DirectoryProperty outputs
  • preserve the existing generatedSourcesDir, schemaPaths, getOutputDir, and getExampleOutputDir DSL/JVM accessors as compatibility bridges
  • disable cache storage and loading only when generated Jakarta annotations include timestamps
  • add TestKit coverage for cross-workspace cache reuse, output equivalence, up-to-date behavior, input invalidation, and the timestamped-output opt-out

Validation

JAVA_HOME=/Users/isobolevska/.sdkman/candidates/java/17.0.19-zulu ./gradlew \
  :graphql-dgs-codegen-gradle:formatKotlinMain \
  :graphql-dgs-codegen-gradle:formatKotlinTest \
  :graphql-dgs-codegen-gradle:validatePlugins \
  :graphql-dgs-codegen-gradle:test --no-scan

BUILD SUCCESSFUL on Gradle 9.4.1. The cross-directory TestKit test reports FROM-CACHE; the unchanged local rerun reports UP-TO-DATE; changed scalar, boolean, map, list, and schema inputs execute the task again.

Adversarial review

An independent line-by-line review of commit c1963d11 found no correctness issues after verification:

  • all three new TestKit tests and the complete Gradle plugin test suite pass
  • mutation-testing doNotCacheIf to always return false makes the timestamped-annotation test fail because the second workspace goes FROM-CACHE, proving the opt-out test detects the regression
  • validatePlugins --rerun passes without missing-annotation or overlapping-output warnings, including the two DirectoryProperty outputs and the @Internal compatibility accessors
  • existing provider, file-collection, mutable-list and multimodule DSL compatibility fixtures pass
  • the cross-workspace helper's output-root substitution was checked against the exact fixture text, ruling out accidental shared output paths

The review also confirmed that the self-assignment in init intentionally invokes the custom setter for the initialized default, flatMap(GenerateJavaTask::generatedSourcesDirectory) preserves lazy source-set wiring, and the cache predicate reads the final configured values at execution time.

The example output directory remains outside Gradle source-set wiring, as it was before this change; that pre-existing behavior is out of scope.

Benchmark

An external consumer fixture using a shared local cache executed generateJava in the first workspace and restored it FROM-CACHE in a second absolute workspace path. The generated output trees were byte-identical. End-to-end wall time was 19.51s for the initial included-build run and 0.88s for the warm cached run. This is directional because the first number includes daemon and included-build setup; the material result is that code generation is skipped entirely on the cache hit.

@iuliiasobolevska
iuliiasobolevska force-pushed the perf/cacheable-generate-java branch from c1963d1 to c488b60 Compare September 23, 2026 20:35
@iuliiasobolevska
iuliiasobolevska force-pushed the perf/cacheable-generate-java branch from c488b60 to 11c5109 Compare September 24, 2026 00:50
@iuliiasobolevska
iuliiasobolevska merged commit f40f4a2 into master Sep 24, 2026
2 checks passed
@iuliiasobolevska
iuliiasobolevska deleted the perf/cacheable-generate-java branch September 24, 2026 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants