Skip to content

Improve cacheability of agent shadowJar task#11878

Open
PerfectSlayer wants to merge 3 commits into
masterfrom
bbujon/ci
Open

Improve cacheability of agent shadowJar task#11878
PerfectSlayer wants to merge 3 commits into
masterfrom
bbujon/ci

Conversation

@PerfectSlayer

Copy link
Copy Markdown
Contributor

What Does This Do

This PR removes the custom actions (filesMatching with closures) that prevent the task to be cached by Gradle.
It uses the default shadow jar mechanisms instead:

  • resource transformers to merge service files and keep only a single copy of duplicate license files
  • failOnDuplicateEntries that ensure the zip file do not have duplicate entry

This is needed as resource duplication is needed for the transformer to merge them but the failOnDuplicateEntries is the safety check that there won’t be duplicate after resource transformation.

Motivation

The goal is to help with build cache and avoiding recreating the JARs when publishing them to maven central - so it’s effectively the same artefact that will be tested and published.

Additional Notes

I have additional ideas for the index generation too I need to review first before making a PR with.

Contributor Checklist

  • Format the title according to the contribution guidelines
  • Assign the type: and (comp: or inst:) labels in addition to any other useful labels
  • Avoid using close, fix, or any linking keywords when referencing an issue
    Use solves instead, and assign the PR milestone to the issue
  • Update the CODEOWNERS file on source file addition, migration, or deletion
  • Update public documentation with any new configuration flags or behaviors
  • Add your completed PR to the merge queue by commenting /merge. You can also:
    • Customize the commit message associated with the merge with /merge --commit-message "..."
    • Remove your PR from the merge queue with /merge -c
    • Skip all merge queue checks with /merge -f --reason "reason"; please use this judiciously, as some checks do not run at the PR-level (note: the PR still needs to be mergeable, this will only skip the pre-merge build)
    • Get more information in this doc

Jira ticket: [PROJ-IDENT]

@PerfectSlayer PerfectSlayer added the tag: no release notes Changes to exclude from release notes label Jul 7, 2026
@PerfectSlayer PerfectSlayer requested a review from a team as a code owner July 7, 2026 18:03
@PerfectSlayer PerfectSlayer added the comp: tooling Build & Tooling label Jul 7, 2026
@PerfectSlayer PerfectSlayer requested a review from dougqh July 7, 2026 18:03
@datadog-datadog-prod-us1

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.76 s 14.80 s [-1.2%; +0.6%] (no difference)
startup:insecure-bank:tracing:Agent 13.66 s 13.68 s [-0.9%; +0.6%] (no difference)
startup:petclinic:appsec:Agent 16.86 s 16.78 s [-0.3%; +1.3%] (no difference)
startup:petclinic:iast:Agent 16.29 s 16.95 s [-8.0%; +0.3%] (no difference)
startup:petclinic:profiling:Agent 16.70 s 16.79 s [-1.4%; +0.4%] (no difference)
startup:petclinic:sca:Agent 16.91 s 16.80 s [-0.4%; +1.8%] (no difference)
startup:petclinic:tracing:Agent 16.18 s 15.74 s [-1.5%; +7.0%] (no difference)

Commit: dcf15a0e · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@bric3 bric3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good find the transformer looks like the modern way achieve this.

I had to look why the actions, while serializable (as they do not capture any state), did not allow caching. Turns out that fileMatching calls behind the hood eachFile which toggle a flag hasCustomActions , and this flag is is queried upon asking if this task should cache its outputs.

        this.getOutputs().doNotCacheIf(
            "Has custom actions",
            spec(task -> rootSpec.hasCustomActions())
        );

Comment thread dd-java-agent/build.gradle Outdated

// Vendored dependencies repeat license/notice metadata; keep a single copy
transform(PreserveFirstFoundResourceTransformer) {
it.resources.addAll(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: This API is deprecated.

Suggested change
it.resources.addAll(
it.include(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I have a hard time with groovy and API discovery 😬

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in cb39b34

Comment thread dd-java-agent/build.gradle Outdated
// Allow duplicate to merge service files
duplicatesStrategy = INCLUDE
// Ensure there is no duplicate in the final jar after resource transformer applied
failOnDuplicateEntries.set(true)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: The .set should not be needed

Suggested change
failOnDuplicateEntries.set(true)
failOnDuplicateEntries = true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in cb39b34

@bric3

bric3 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

By the way, I'd like to note that any call on the CopySpec methods (inherited any archive tasks), will disable caching, they almost all invoke under the hood DefaultCopySpec.appendCopyAction that toggle the flag mentioned above.

@PerfectSlayer PerfectSlayer requested a review from a team as a code owner July 8, 2026 11:48
Comment on lines +77 to +79
transform<ApacheLicenseResourceTransformer>()
transform<ApacheNoticeResourceTransformer>()
failOnDuplicateEntries = true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

praise: Good idea.

@mhdatie

mhdatie commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Curious, how do you go about testing this change?

Also, similar to my concern in #11856, what happens if failOnDuplicateEntries resolves to true and what are the steps to correct the build?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: tooling Build & Tooling tag: no release notes Changes to exclude from release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants