← Back to DAGDA | Support | Source: https://github.com/gradle/gradle/pull/38952
Skip to content

Document supported WorkParameters types - #38952

Merged
lkasso merged 2 commits into
gradle:masterfrom
exijn:issue-38765-work-parameters-docs
Aug 26, 2026
Merged

lkasso merged 2 commits into
gradle:masterfrom
exijn:issue-38765-work-parameters-docs

Conversation

@exijn

@exijn exijn commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #38765

Summary

  • Document how Gradle creates isolated copies of WorkParameters and distinguish this from the additional IPC serialization required by processIsolation().
  • Reorganize the guidance around Gradle managed types, including scalar, file, collection, named object, and build service parameters.
  • Explain that Gradle model containers such as NamedDomainObjectContainer are unsupported and that Java serialization is a last-resort fallback with input tracking and configuration-cache trade-offs.

Verification

  • ./gradlew.bat :docs:userguideMultiPage — passed; the task reported existing configuration-cache problems from the documentation/Asciidoctor dependency graph and discarded that cache entry.
  • ./gradlew.bat :workers:embeddedIntegTest --tests org.gradle.workers.internal.WorkerExecutorParametersIntegrationTest --tests org.gradle.workers.internal.WorkerExecutorParametersKotlinIntegrationTest --console=plain — passed.
  • Reviewed existing coverage in DefaultIsolatableFactoryTest and the WorkerParameters integration tests.
  • .\gradlew.bat :docs:checkDeadInternalLinks --console=plain — passed; the documentation link check completed successfully.
  • .\gradlew.bat :docs:userguideMultiPage --console=plain — passed; Gradle reported 18 existing configuration-cache problems from the documentation/Asciidoctor dependency graph and discarded that cache entry.
  • .\gradlew.bat :workers:embeddedIntegTest --tests org.gradle.workers.internal.WorkerExecutorParametersIntegrationTest --tests org.gradle.workers.internal.WorkerExecutorParametersKotlinIntegrationTest --rerun-tasks --console=plain — passed; both Worker parameters integration test classes executed successfully.
  • git diff --check — passed.
  • .\gradlew.bat :docs:checkDeadInternalLinks --no-configuration-cache --console=plain — could not run because this checkout enables Isolated Projects, which does not allow disabling the configuration cache; the same check passed with the repository default configuration.

Signed-off-by: hej090224 <fc49854985@gmail.com>
@exijn
exijn requested a review from a team as a code owner August 25, 2026 08:21
@bot-gradle bot-gradle added from:contributor PR by an external contributor to-triage labels Aug 25, 2026
@lkasso lkasso added in:workers a:documentation Documentation content labels Aug 26, 2026
@lkasso lkasso added this to the 9.9.0 RC1 milestone Aug 26, 2026
@lkasso lkasso removed the to-triage label Aug 26, 2026

@lkasso lkasso left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for tackling this — the information is genuinely useful, and the NamedDomainObjectContainer warning in particular is a common gotcha worth documenting. A few things I'd like us to adjust before merging:

Placement. The new subsection sits between "Step 2. Convert to the Worker API" and "Step 3. Change the isolation mode," which interrupts the numbered walkthrough. It reads better as a peer top-level section between "Worker Daemons" and "Cancellation and timeouts."

Isolation mechanism (line 173). The current wording — "copied for noIsolation(), and are serialized and sent to the worker for classLoaderIsolation() and processIsolation()" — isn't quite right. All three modes take an isolated copy of the parameters via IsolatableFactory.isolate(params). Only processIsolation() additionally serializes them for IPC to the worker daemon (see DefaultActionExecutionSpecFactory#newIsolatedSpec and #newTransportableSpec).

Provider<T> in the managed-types list (line 180). A raw Provider<T> getter on a WorkParameters interface isn't wired up as a managed property — AbstractClassGenerator#isPropertyType only recognizes Property, HasMultipleValues, and MapProperty. Recommending Property<T> is the safer, more idiomatic guidance.

NamedDomainObjectContainer failure mode (line 192). "Container type is not preserved during isolation" implies partial success. The real failure is at serialization time: containers aren't Serializable, so the fallback path fails outright.

Shape. The list is exhaustive but doesn't tell readers what to reach for by default. It reads more usefully with a small example interface at the top, a "prefer managed types" section with a type-mapping table and the why (lazy, CC-friendly, fingerprinted), and the Serializable fallback framed as a last resort with explicit costs rather than as a peer option.

Here's a suggested rewrite. Two steps: (1) delete the section from its current location in the walkthrough, (2) add this new top-level section between "Worker Daemons" and "Cancellation and timeouts":

[[work_parameter_types]]
== Work parameter types

A `WorkParameters` type is an interface that declares a getter for each value the work action needs.
A typical parameters interface looks like this:

[source,java]
----
public interface MyWorkParameters extends WorkParameters {
    Property<String> getMessage();
    RegularFileProperty getOutputFile();
    ConfigurableFileCollection getInputFiles();
    ListProperty<String> getFlags();
}
----

Before executing the work, Gradle takes an isolated copy of the parameters.
The work action reads from that copy, so changes made to the parameter objects after `submit()` do not affect the running work.
For `processIsolation()`, Gradle also serializes the parameters to transport them to the worker daemon process.

=== Prefer Gradle managed types

Use Gradle managed types for parameter values wherever possible.
Managed types are lazy, isolatable, and compatible with the <<configuration_cache.adoc#config_cache,configuration cache>>, and they let Gradle fingerprint parameter values for up-to-date checks and the build cache.

[cols="1,2"]
|===
|Use |For

|link:{javadocPath}/org/gradle/api/provider/Property.html[`Property<T>`]
|A single scalar value

|link:{javadocPath}/org/gradle/api/file/RegularFileProperty.html[`RegularFileProperty`], link:{javadocPath}/org/gradle/api/file/DirectoryProperty.html[`DirectoryProperty`]
|A file or directory location

|link:{javadocPath}/org/gradle/api/file/ConfigurableFileCollection.html[`ConfigurableFileCollection`]
|A collection of files

|link:{javadocPath}/org/gradle/api/provider/ListProperty.html[`ListProperty<T>`], link:{javadocPath}/org/gradle/api/provider/SetProperty.html[`SetProperty<T>`], link:{javadocPath}/org/gradle/api/provider/MapProperty.html[`MapProperty<K, V>`]
|A collection of values

|link:{javadocPath}/org/gradle/api/Named.html[`Named`] objects, <<build_services.adoc#build_services,build services>>
|Named or shared state
|===

Plain scalar values (`String`, `Boolean`, boxed primitives, enums, `File`, `null`) are also isolatable and work as parameter values, but wrapping them in a `Property<T>` defers value resolution and lets Gradle track the input.

=== Types to avoid

Gradle model containers such as link:{javadocPath}/org/gradle/api/NamedDomainObjectContainer.html[`NamedDomainObjectContainer`] are not supported as work parameters.
They are not `Serializable`, so isolation fails when the work is submitted.
Represent their contents with a collection property such as `SetProperty<T>` or `ListProperty<T>`, or `MapProperty<String, T>` if you need to preserve names.

=== Java serialization fallback

Values that do not match the types above fall back to Java serialization if they implement `java.io.Serializable`.
Avoid this path when possible: serialized values are opaque to Gradle's input fingerprinting and lazy evaluation, so they weaken up-to-date checks and configuration cache reuse.
An unsupported or non-serializable value causes parameter isolation to fail when the work is submitted.

I verified the rewrite against the code (AbstractValueProcessor, DefaultActionExecutionSpecFactory, AbstractClassGenerator) and ran ./gradlew :docs:checkDeadInternalLinks locally — all cross-references resolve. Thanks again for the contribution!

Signed-off-by: hej090224 <fc49854985@gmail.com>
@exijn

exijn commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review and suggested structure. I moved the content into a standalone top-level section between Worker Daemons and Cancellation and timeouts, corrected the isolation and process-isolation serialization explanation, and reorganized the guidance around managed types with a type-mapping table. I also clarified the unsupported NamedDomainObjectContainer failure and framed Java serialization as a last-resort fallback with its input tracking, up-to-date check, and configuration cache trade-offs.

Validation passed:

  • .\gradlew.bat :docs:checkDeadInternalLinks --console=plain
  • .\gradlew.bat :docs:userguideMultiPage --console=plain (with the existing documentation configuration-cache problems reported and discarded)
  • .\gradlew.bat :workers:embeddedIntegTest --tests org.gradle.workers.internal.WorkerExecutorParametersIntegrationTest --tests org.gradle.workers.internal.WorkerExecutorParametersKotlinIntegrationTest --rerun-tasks --console=plain

The PR is ready for another look.

@lkasso
lkasso added this pull request to the merge queue Aug 26, 2026
Merged via the queue into gradle:master with commit 148a529 Aug 26, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a:documentation Documentation content from:contributor PR by an external contributor in:workers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document which types are supported in WorkParameters

3 participants