fix(build-logic): publish component in afterEvaluate to fix shadow variant race#33
Merged
Merged
Conversation
…luate The shadow plugin registers its shadowRuntimeElements variant on the java component from an afterEvaluate hook. Calling publication.from(component) at apply time left publish computing componentArtifacts before that hook ran under CI's injected plugins, failing every library publish with "Variant for configuration 'shadowRuntimeElements' does not exist in component 'java'". Bind the component in afterEvaluate so the variant is registered first; shaded modules still publish their :all variant.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR adjusts the Maven publishing build logic so that the Java component is bound to the publication in an afterEvaluate block, ensuring the shadowRuntimeElements variant from the Shadow plugin is registered before Gradle computes publication component artifacts, preventing CI-only race failures. Sequence diagram for Gradle evaluation and Java component binding afterEvaluatesequenceDiagram
participant Gradle
participant Project
participant ShadowPlugin
participant MagicUtilsPublishingPlugin
participant Publication
participant JavaComponent
Gradle->>Project: apply ShadowPlugin
Project->>ShadowPlugin: afterEvaluate
note over ShadowPlugin: registers shadowRuntimeElements on JavaComponent
Gradle->>Project: apply MagicUtilsPublishingPlugin
Project->>MagicUtilsPublishingPlugin: configure publishing
MagicUtilsPublishingPlugin->>Project: afterEvaluate
note over MagicUtilsPublishingPlugin: bind JavaComponent to Publication
Project->>Publication: publication.from(JavaComponent)
note over Publication,JavaComponent: JavaComponent includes shadowRuntimeElements variant
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- It may be worth guarding
publication.from(project.components.getByName("java"))with a check that thejavacomponent exists so this plugin fails more gracefully on non-Java projects or when the Java component is configured differently.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- It may be worth guarding `publication.from(project.components.getByName("java"))` with a check that the `java` component exists so this plugin fails more gracefully on non-Java projects or when the Java component is configured differently.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
The 1.23.0 publish-maven run failed on every library target with:
Root cause: the shadow plugin registers its
shadowRuntimeElementsvariant on thejavacomponent from anafterEvaluatehook.publication.from(components["java"])was called at apply time, so under CI (wheresetup-gradleinjects extra plugins that reorderafterEvaluatehooks) publish computedcomponentArtifactsbefore the variant was registered. It reproduced deterministically on CI but not locally.Fix: bind the component in
afterEvaluate, after shadow's registration. Shaded modules (config/lang) still publish their:allvariant; plain modules andpublishToMavenLocalverified locally.Summary by Sourcery
Bind Maven publication components in an afterEvaluate hook to ensure the shadowRuntimeElements variant is registered before publishing and avoid CI race failures.
Bug Fixes:
Build: