Skip to content

feat(pkl-gradle): Implement gradle configuration cache support#1500

Merged
bioball merged 1 commit intoapple:mainfrom
ffluk3:gradle-configuration-cache
Apr 21, 2026
Merged

feat(pkl-gradle): Implement gradle configuration cache support#1500
bioball merged 1 commit intoapple:mainfrom
ffluk3:gradle-configuration-cache

Conversation

@ffluk3
Copy link
Copy Markdown
Contributor

@ffluk3 ffluk3 commented Apr 6, 2026

Fixes #1425

Gradle's configuration cache is one of the more impactful performance features in modern Gradle. It serializes the task graph after the first configuration phase so subsequent builds can skip it entirely. For large projects this can mean the difference between a multi-second configuration overhead and near-instant task scheduling.

The root cause preventing pkl-gradle from adopting the configuration cache was a handful of patterns the configuration cache explicitly prohibits: holding a reference to the Project object in a plugin field, accessing getProject() inside task action code at execution time, and caching CLI option objects that close over non-serializable state. These patterns work fine in a standard Gradle build, but they prevent Gradle from safely serializing the task graph to disk.

What changed

PKL Plugin rework

The most visible structural change in PklPlugin is the removal of the @LateInit private Project project field. Rather than storing the project on the plugin instance, it's now passed as a parameter through the configure call chain. This is a mechanical but pervasive refactor, since every configure* method gains a project argument and passes via property drilling.

Per-task changes

  • BasePklTask captures project.getLayout().getProjectDirectory() at configuration time into a getWorkingDir() DirectoryProperty, rather than calling getProject().getProjectDir() at execution time. CliBaseOptions is now constructed fresh each time it's needed inside a task action, which is a trade-off between the (potentially negligible) cost of construction, and caching it, which would require holding a cross-boundary reference that defeats the configuration cache.
  • EvalTask's lazily-cached Provider<CliEvaluator> is similarly replaced with a factory method, and JavaCodeGenTask and KotlinCodeGenTask leverage the output dir.
  • In ModulesTask, getTransitiveModules() changes from a ListProperty<File> to a ConfigurableFileCollection (enabling .from() wiring rather than .set()), and gains a @PathSensitive(ABSOLUTE) annotation so the task doesn't unnecessarily re-run when files are moved between machines but their content and paths are unchanged. The parsedSourceModulesCache map is also removed — it was there to avoid redundant parsing but is incompatible with the cache since it holds mutable state across invocations.

Cleanup

The AnalyzeImportsTask no longer wraps CliImportAnalyzer construction in a lazily-cached Provider; instead it constructs the analyzer inline inside doRunTask(), consistent with the other task types. The transitive-import parsing logic in PklPlugin and PluginUtils is unchanged.

Tests

Each task type gets a new is configuration cache compatible test that runs the task twice with --configuration-cache and asserts that the first run stores a cache entry and the second reuses it. The test infrastructure for this lives in a new runTaskWithConfigurationCache helper on AbstractTest. NOTE: these tests run slightly slower than the rest of the suite because they need the forked Gradle process to execute twice to prove out configuraion cache usage.

Copy link
Copy Markdown
Contributor

@HT154 HT154 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just one little nit.

This seems reasonable to me, but I'm going to defer to @bioball's greater Gradle expertise for final approval.

Comment thread pkl-gradle/src/main/java/org/pkl/gradle/task/ModulesTask.java Outdated
@ffluk3 ffluk3 force-pushed the gradle-configuration-cache branch from 0c63abb to 4e4fd66 Compare April 7, 2026 15:51
Comment thread pkl-gradle/src/main/java/org/pkl/gradle/task/ModulesTask.java Outdated
@ffluk3 ffluk3 force-pushed the gradle-configuration-cache branch from 4e4fd66 to 7034d01 Compare April 7, 2026 17:46
@HT154 HT154 requested a review from bioball April 7, 2026 18:11
@ffluk3 ffluk3 force-pushed the gradle-configuration-cache branch from 7034d01 to 1197bec Compare April 9, 2026 20:32
@ffluk3
Copy link
Copy Markdown
Contributor Author

ffluk3 commented Apr 13, 2026

Good morning @bioball! Please let me know if there are other requests or questions around getting this verified or merged in. Happy to help out where I can!

@bioball
Copy link
Copy Markdown
Member

bioball commented Apr 13, 2026

Hi! This is on my list of TODOs. I haven't forgotten about it! Apologies, my availability is quite limited right now so I haven't gotten to a review yet.

@ffluk3
Copy link
Copy Markdown
Contributor Author

ffluk3 commented Apr 13, 2026

No problem at all! Appreciate both of your time managing and maintaining the project 😄

Copy link
Copy Markdown
Member

@bioball bioball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! This mostly looks great. I have just a few comments.

Also, would love some eyes from @netvl, who wrote much of the code in our Gradle plugin.

Comment thread pkl-gradle/src/main/java/org/pkl/gradle/task/AnalyzeImportsTask.java Outdated
Comment thread pkl-gradle/src/main/java/org/pkl/gradle/task/AnalyzeImportsTask.java Outdated
Comment thread pkl-gradle/src/main/java/org/pkl/gradle/task/AnalyzeImportsTask.java Outdated
Comment thread pkl-gradle/src/main/java/org/pkl/gradle/PklPlugin.java Outdated
Comment thread pkl-gradle/src/main/java/org/pkl/gradle/task/ModulesTask.java Outdated
Comment thread pkl-gradle/src/test/kotlin/org/pkl/gradle/AbstractTest.kt
@ffluk3 ffluk3 force-pushed the gradle-configuration-cache branch 2 times, most recently from 5240f62 to 70bcc7b Compare April 17, 2026 22:04
@ffluk3
Copy link
Copy Markdown
Contributor Author

ffluk3 commented Apr 17, 2026

Thanks @bioball! All feedback should be addressed now 😄

Copy link
Copy Markdown
Member

@bioball bioball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! This looks great! I'll wait to see if @netvl wants to provide some comments before merging this.

Some small nits to fix.

Comment thread pkl-gradle/src/main/java/org/pkl/gradle/PklPlugin.java Outdated
Comment thread pkl-gradle/src/main/java/org/pkl/gradle/task/AnalyzeImportsTask.java Outdated
@ffluk3 ffluk3 force-pushed the gradle-configuration-cache branch 3 times, most recently from 250be21 to 990ce5a Compare April 20, 2026 17:21
@ffluk3
Copy link
Copy Markdown
Contributor Author

ffluk3 commented Apr 20, 2026

LGTM, thanks! This looks great! I'll wait to see if @netvl wants to provide some comments before merging this.

Some small nits to fix.

Thanks! Feedback incorporated and I squashed to a single commit.

Copy link
Copy Markdown
Contributor

@netvl netvl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of questions, overall looks awesome!

Comment thread pkl-gradle/src/main/java/org/pkl/gradle/PklPlugin.java
Comment thread pkl-gradle/src/main/java/org/pkl/gradle/PklPlugin.java Outdated
Modern versions of Gradle support configuration caching
to prevent the gradual increase of project size to affect
the overall developer experience of Gradle builds. To
prepare the PKL project, and specificall pkl-gradle, for
configuration support, we introduce an integration test to
vet configuration cache rules, and then perform the necessary
updates to provide configuration cache support.

Fixes apple#1425
@ffluk3 ffluk3 force-pushed the gradle-configuration-cache branch from 990ce5a to 56b149a Compare April 20, 2026 23:21
@ffluk3
Copy link
Copy Markdown
Contributor Author

ffluk3 commented Apr 20, 2026

Just a couple of questions, overall looks awesome!

@netvl thanks for your review! I was able to roll back my null checks, plus some more helpful exception messages on missing sourcesets.

@bioball bioball merged commit d4dacd5 into apple:main Apr 21, 2026
21 checks passed
@ffluk3
Copy link
Copy Markdown
Contributor Author

ffluk3 commented Apr 21, 2026

Hey @bioball thanks for merging this! It was great to collaborate to get this update in.

Quick question on the release cadence: I know your minor revisions will be frequently deployed Feb/Jun/Oct per your roadmap. Having said that, will there be any plans to cut this change (and the existing merged) as a patch before June? Our team is excited to make use of this enhancement!

Thanks again.

@bioball
Copy link
Copy Markdown
Member

bioball commented Apr 21, 2026

We generally don't put behavior changes into patch versions. So, alas, this change will be part of the 0.32 release cycle!

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.

Support the Gradle Configuration Cache with pkl-gradle

4 participants