Skip to content

fix(build-logic): publish component in afterEvaluate to fix shadow variant race#33

Merged
THEROER merged 1 commit into
mainfrom
fix/publish-shadow-component
Jul 6, 2026
Merged

fix(build-logic): publish component in afterEvaluate to fix shadow variant race#33
THEROER merged 1 commit into
mainfrom
fix/publish-shadow-component

Conversation

@THEROER

@THEROER THEROER commented Jul 6, 2026

Copy link
Copy Markdown
Owner

The 1.23.0 publish-maven run failed on every library target with:

Variant for configuration 'shadowRuntimeElements' does not exist in component 'java'. For a given configuration, 'addVariantsFromConfiguration' must be called before 'withVariantsFromConfiguration'.

Root cause: the shadow plugin registers its shadowRuntimeElements variant on the java component from an afterEvaluate hook. publication.from(components["java"]) was called at apply time, so under CI (where setup-gradle injects extra plugins that reorder afterEvaluate hooks) publish computed componentArtifacts before 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 :all variant; plain modules and publishToMavenLocal verified 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:

  • Fix Maven publishing failures for shadowed Java components by deferring component binding until after shadow variant registration.

Build:

  • Adjust Gradle publishing logic to configure publication sources in afterEvaluate instead of at plugin apply time to be compatible with shadow plugin behavior.

…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.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@sourcery-ai

sourcery-ai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This 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 afterEvaluate

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Delay binding the Java software component to the publication until after project evaluation to avoid a race with the Shadow plugin’s variant registration.
  • Replace direct publication.from(components["java"]) call at plugin apply time with a project.afterEvaluate block
  • Inside afterEvaluate, bind the java component to the publication using publication.from(project.components.getByName("java"))
  • Document in comments the rationale about shadowRuntimeElements variant registration timing and CI plugin ordering issues
build-logic/src/main/kotlin/dev/ua/theroer/magicutils/build/publish/MagicUtilsPublishingPlugin.kt

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot 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.

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@THEROER THEROER merged commit 74baa05 into main Jul 6, 2026
8 checks passed
@THEROER THEROER deleted the fix/publish-shadow-component branch July 10, 2026 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant