Skip to content

[MDEP-726] Resolve artifact item versions from transitive dependencies - #1667

Open
wilx wants to merge 4 commits into
apache:masterfrom
wilx:issue-1240-transitive-artifact-version
Open

[MDEP-726] Resolve artifact item versions from transitive dependencies#1667
wilx wants to merge 4 commits into
apache:masterfrom
wilx:issue-1240-transitive-artifact-version

Conversation

@wilx

@wilx wilx commented Aug 1, 2026

Copy link
Copy Markdown

Summary

Allow dependency:copy and dependency:unpack artifact items to omit their version when the artifact is present only as a transitive project dependency.

The existing direct-dependency and dependency-management lookups remain authoritative. If neither supplies a version, the plugin lazily collects the requested compile, runtime, or test dependency graph through Maven Resolver and looks up the selected artifact version. An optional dependencyScope setting resolves cases where different classpaths select different versions; without it, conflicting selections are reported rather than guessed.

Artifact matching first uses the complete group ID, artifact ID, type, and classifier coordinates and then preserves the existing GA fallback. The resolved graphs are cached per scope in immutable GA-indexed maps. Existing relocation behavior is retained because the original model coordinates are checked before Resolver's post-relocation graph.

This implementation uses the Maven shared dependency graph APIs supported by both Maven 3.x and Maven 4.x.

Fixes #1240.

Verification

  • mvn verify — 415 tests passed, with one existing skip.
  • mvn -Prun-its verify — all 103 integration projects passed.
  • Focused mdep-726-*, copy-relocation, and unpack-relocation integration tests passed with:
    • Maven 3.6.3 on JDK 8
    • Maven 3.9.16 on JDK 21
    • Maven 4.0.0-rc-5 on JDK 21
  • Spotless, Checkstyle, Apache RAT, dependency analysis, and git diff --check passed.

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 integration tests successfully (mvn -Prun-its verify).

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.

Allow copy and unpack artifact items to infer omitted versions from scope-specific dependency graphs while preserving direct dependency and dependency-management lookup.

Fixes apache#1240.
@wilx
wilx marked this pull request as ready for review August 1, 2026 19:21
@elharo elharo added the enhancement New feature or request label Aug 2, 2026
<artifactItem>
<groupId>org.apache.maven.its.dependency</groupId>
<artifactId>ResourceArtifact-relocation</artifactId>
<version>1.0</version>

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.

we should probably keep the existing test as is and add new ones without the version

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I reverted this and added separate tests.

ArtifactHandlerManager artifactHandlerManager,
RepositorySystem repositorySystem,
ResolverUtil resolverUtil) {
ResolverUtil resolverUtil,

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.

This incompatibly changes a published API

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

There is not a single use that is outside of this plugin that I could find in any Maven sources.

But I will try to preserve the signature.

@wilx wilx Aug 2, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I reverted the signature change.

/**
* Classpath scope from which to infer a missing version when the artifact is not found in direct dependencies or
* dependency management. Supported values are {@code compile}, {@code runtime}, and {@code test}. When omitted,
* all three dependency graphs are considered and must agree on the selected version.

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.

what if they don't agree?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Then it is an error and the user has to deal with it by either specifying the dependencyScope or by giving explicit version`.

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.

will this mean users now get errors on projects where they saw no errors before?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

No. This entire patch is strictly improving the situation. Before the patch, you had to add the version explicitly. With the patch, you can omit the version and it will get resolved but it has to be unambiguous.

* @since 3.11.1
*/
@Parameter
private String dependencyScope;

@elharo elharo Aug 2, 2026

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.

scope is different than the other fields. They're about the artifact itself. This is about how the artifact is used. This might be confusing artifacts and dependencies on artifacts. An artifact doesn't really have a scope.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

See above. This is used to guide the dependency version resolution for the artifact if the version is ambiguous due to different version of the artifact in different scopes.

@wilx

wilx commented Aug 3, 2026

Copy link
Copy Markdown
Author

I have pushed the formatting fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MDEP-726] dependency:copy finds missing versions in TRANSITIVE dependencies

2 participants