Make assemble depend on shadowJar even if it is added later#1766
Merged
Goooler merged 5 commits intoGradleUp:mainfrom Sep 20, 2025
Merged
Make assemble depend on shadowJar even if it is added later#1766Goooler merged 5 commits intoGradleUp:mainfrom
assemble depend on shadowJar even if it is added later#1766Goooler merged 5 commits intoGradleUp:mainfrom
Conversation
The functional test checks for the existence of the task object in the `dependsOn` set, and I was adding the task provider instead.
Member
It works now. |
Goooler
reviewed
Sep 20, 2025
Comment on lines
+542
to
+545
| // Can't use `named` directly as the task is optional or may not exist when the plugin is applied. | ||
| // Using Spec<String> applies the action to the task if it is added later. | ||
| tasks.named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME::equals).configureEach { | ||
| it.dependsOn(task) |
Member
There was a problem hiding this comment.
This looks could be moved into the upper block.
Member
There was a problem hiding this comment.
We can't. TaskProvider should be passed into dependsOn. See #1768.
assemble depend on shadowJar even if it is added later
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, Shadow makes the assemble task depend on shadowJar if and only if it exists when the shadow plugin is applied. This is usually fine, but in the case of some unorthodox setups, it can mean that if the Shadow plugin is applied before the base plugin, the assemble task can end up existing without depending on the shadowJar task.
To address this, instead of using
TaskContainer#findByName(String), we can use#named(Spec<String>)to work with a live view of the container. This is very similar to how#withType(Class<S extends T>works, whereconfigureEachapplies the action to each member that passes the spec, even if it is added later.The only thing I don't know what to do now with this PR is how to write tests for it. I'd appreciate your help with that. Thanks!
For the record, you can easily test this using this snippet. Apologies for the Groovy DSL 😛