GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Preserve dependency scope in plugin artifacts - fix #12497 by slawekjaranowski · Pull Request #12503 · apache/maven

Conversation

@slawekjaranowski

@slawekjaranowski slawekjaranowski commented Jul 18, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

What changed:

  • Added RepositoryUtils.toArtifact(ArtifactResult) to convert resolved artifacts and copy dependency metadata from - Made RepositoryUtils.toArtifact(Dependency) public (was package-private).
  • Added private DefaultMavenPluginManager.toMavenArtifacts(DependencyResult) that iterates over dependency graph nodes instead of raw artifact results.
  • Used toMavenArtifacts for both plugin realm and extension artifact resolution.

Why:

  • PluginDescriptor.getArtifacts() returned artifacts with null scope in Maven 3.10.0-rc-1.
  • Restoring scope/optional metadata brings behavior back in line with 3.9.x and avoids regressions in plugins that depend on artifact scope.

Analogous fix was applied to Maven 4 in #1928

fix #12497

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
    This may not always be possible but is a best-practice.
  • Run mvn verify to make sure basic checks pass.
    A more thorough check will be performed on your pull request automatically.
  • You have run the Core IT successfully.

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

  • I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004
  • In any other case, please file an Apache Individual Contributor License Agreement.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@slawekjaranowski
slawekjaranowski requested a review from cstamas July 18, 2026 12:58
@slawekjaranowski slawekjaranowski linked an issue Jul 18, 2026 that may be closed by this pull request
PluginDescriptor.getArtifacts() returns Artifact instances with null scope #12497
Closed
@slawekjaranowski slawekjaranowski added this to the 3.10.0 milestone Jul 18, 2026
@slawekjaranowski slawekjaranowski added the bug Something isn't working label Jul 18, 2026
@slawekjaranowski
slawekjaranowski force-pushed the fix-12497 branch from d51a7ab to 4ae9f94 Compare July 18, 2026 13:01
@slawekjaranowski
slawekjaranowski requested a review from gnodet July 18, 2026 13:01
@slawekjaranowski slawekjaranowski self-assigned this Jul 18, 2026
cstamas
cstamas approved these changes Jul 18, 2026
View reviewed changes
gnodet
gnodet approved these changes Jul 18, 2026
View reviewed changes

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

AI Review — PR #12503

Verdict: ✅ APPROVE

Summary: This PR correctly fixes a regression in 3.10.0-rc-1 where PluginDescriptor.getArtifacts() returned artifacts with null scope. The new RepositoryUtils.toArtifact(ArtifactResult) overload navigates the ArtifactResult → ArtifactRequest → DependencyNode → Dependency chain to recover scope and optional metadata. The approach is minimal, null-safe via Optional, and follows existing codebase patterns.

Findings

Important — CI Spotless failure
RepositoryUtils.java line 177: Spotless rejects the space before the closing ) — } ); should be });. All three build jobs fail at spotless:check. Running mvn spotless:apply -B in maven-core will fix it.

// Current (fails Spotless):
                } );
// Fix:
                });

Suggestion — Javadoc
The new method only has @since 3.10.0. A brief description would help future readers:

/**
 * Converts a resolved {@link ArtifactResult} to a Maven Artifact,
 * preserving dependency scope and optional flag from the resolution
 * request's dependency node.
 *
 * @since 3.10.0
 */

Suggestion — Test coverage
No test for the new toArtifact(ArtifactResult) overload. A test verifying scope/optional preservation through the ArtifactResult → DependencyNode → Dependency chain would help prevent this regression from resurfacing.

What I Appreciate

  • Follows existing patterns precisely — the private toArtifact(Dependency) already does setScope()/setOptional(), and this recovers the same info from the ArtifactResult path.
  • Null-safety via Optional.ofNullable(...).map(...).map(...).ifPresent(...) — if any link is absent, the artifact retains its prior state gracefully.
  • The method reference change in DefaultMavenPluginManager is clean and unambiguous.
  • Backward compatible — the root plugin artifact with null scope gets a no-op setScope(null).

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of Guillaume Nodet

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
gnodet added a commit to gnodet/maven that referenced this pull request Jul 18, 2026
@gnodet @claude
chore: update PR review loop state
fb55cf2
Review posted for apache#12503 (preserve dependency scope in plugin
artifacts). APPROVED with Spotless formatting note.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@slawekjaranowski
Preserve dependency scope in plugin artifacts
e2b4130
What changed:
- Made RepositoryUtils.toArtifact(Dependency) public (was package-private).
- Added private DefaultMavenPluginManager.toMavenArtifacts(DependencyResult) that iterates over dependency graph nodes instead of raw artifact results.
- Used toMavenArtifacts for both plugin realm and extension artifact resolution.

Why:
- `PluginDescriptor.getArtifacts()` returned artifacts with `null` scope in Maven 3.10.0-rc-1.
- Restoring scope/optional metadata brings behavior back in line with 3.9.x and avoids regressions in plugins that depend on artifact scope.

Analogous fix was applied to Maven 4 in apache#1928

fix apache#12497
@slawekjaranowski
slawekjaranowski force-pushed the fix-12497 branch from 4ae9f94 to e2b4130 Compare July 20, 2026 15:49
@slawekjaranowski

slawekjaranowski commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

@gnodet @cstamas I have checked a master branch if is affected, and make this change similar to #1928

so please review again

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@slawekjaranowski
slawekjaranowski requested review from cstamas and gnodet July 20, 2026 15:55
gnodet
gnodet approved these changes Jul 20, 2026
View reviewed changes

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Re-review: updated approach (force-push e2b4130)

The approach was reworked since my previous review — this version is a significant improvement.

What changed

Previous approach used Optional.ofNullable(r.getDependency()).map(Dependency::getScope) to patch the scope from ArtifactResult into the converted artifact.

New approach shifts to getDependencyNodeResults() (from Resolver 2.0.21, now available after #12504 merged) and converts directly from Dependency via the existing toArtifact(Dependency) method, which already correctly sets scope via result.setScope(dependency.getScope()).

What this PR does well

  • Uses the natural API path — getDependencyNodeResults() gives access to Dependency objects with their scopes intact, eliminating the need for workaround extraction
  • DRY — both createPluginRealm and resolveExtensionArtifacts now share toMavenArtifacts(DependencyResult)
  • Clean API addition — toArtifact(Dependency) promoted from private to public with proper Javadoc and @since 3.10.0
  • Correct filter — n.getArtifact().getPath() != null is a direct check for resolved artifacts, equivalent to the previous ArtifactResult::isResolved

Checklist

Check Status
Tests ✓ Existing IT from previous version still applies
Docs ✓ Javadoc on newly-public method
Public API ✓ Addition only (private → public), @since 3.10.0
CI ⏳ Builds passing, integration tests pending

LGTM — cleaner than the previous version. ✅


Reviewed with Claude Code on behalf of Guillaume Nodet. This review was generated by an AI agent and may contain inaccuracies; please verify all suggestions before applying.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
cstamas
cstamas approved these changes Jul 20, 2026
View reviewed changes
@slawekjaranowski
slawekjaranowski merged commit 5ca34f1 into apache:maven-3.10.x Jul 20, 2026
18 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@slawekjaranowski
slawekjaranowski deleted the fix-12497 branch July 20, 2026 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@cstamas cstamas cstamas approved these changes
@gnodet gnodet gnodet approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@slawekjaranowski slawekjaranowski

Labels

bug Something isn't working

Projects

None yet

Milestone

3.10.0

Development

Successfully merging this pull request may close these issues.

PluginDescriptor.getArtifacts() returns Artifact instances with null scope

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@slawekjaranowski @cstamas @gnodet
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.