Improve cacheability of agent shadowJar task#11878
Conversation
This comment has been minimized.
This comment has been minimized.
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
There was a problem hiding this comment.
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())
);
|
|
||
| // Vendored dependencies repeat license/notice metadata; keep a single copy | ||
| transform(PreserveFirstFoundResourceTransformer) { | ||
| it.resources.addAll( |
There was a problem hiding this comment.
suggestion: This API is deprecated.
| it.resources.addAll( | |
| it.include( |
There was a problem hiding this comment.
Thanks, I have a hard time with groovy and API discovery 😬
| // Allow duplicate to merge service files | ||
| duplicatesStrategy = INCLUDE | ||
| // Ensure there is no duplicate in the final jar after resource transformer applied | ||
| failOnDuplicateEntries.set(true) |
There was a problem hiding this comment.
suggestion: The .set should not be needed
| failOnDuplicateEntries.set(true) | |
| failOnDuplicateEntries = true |
|
By the way, I'd like to note that any call on the |
| transform<ApacheLicenseResourceTransformer>() | ||
| transform<ApacheNoticeResourceTransformer>() | ||
| failOnDuplicateEntries = true |
|
Curious, how do you go about testing this change? Also, similar to my concern in #11856, what happens if |
What Does This Do
This PR removes the custom actions (
filesMatchingwith closures) that prevent the task to be cached by Gradle.It uses the default shadow jar mechanisms instead:
failOnDuplicateEntriesthat ensure the zip file do not have duplicate entryThis is needed as resource duplication is needed for the transformer to merge them but the
failOnDuplicateEntriesis 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
type:and (comp:orinst:) labels in addition to any other useful labelsclose,fix, or any linking keywords when referencing an issueUse
solvesinstead, and assign the PR milestone to the issue/merge. You can also:/merge --commit-message "..."/merge -c/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)Jira ticket: [PROJ-IDENT]