Skip to content

Account for non-test transitive dependency scopes - #294

Open
wilx wants to merge 1 commit into
apache:masterfrom
wilx:mdep-977-non-test-transitive-scopes
Open

Account for non-test transitive dependency scopes#294
wilx wants to merge 1 commit into
apache:masterfrom
wilx:mdep-977-non-test-transitive-scopes

Conversation

@wilx

@wilx wilx commented Aug 1, 2026

Copy link
Copy Markdown

Summary

Avoid recommending test scope for a direct dependency when the same artifact
is still required transitively on the compile or runtime dependency graph.

The analyzer now builds separate compile and runtime graphs without the direct
test-only candidates and suppresses the warning for candidates that remain
reachable. This prevents an unsafe scope change: Maven conflict mediation can
otherwise hide the required transitive artifact behind the direct test-scoped
declaration.

Fixes #295

Validation

  • Maven 3.9.16 / JDK 21: mvn -Prun-its verify
  • Maven 4 / JDK 21: mvn clean -Prun-its verify
  • Maven 3.9.16 / JDK 8: 128 unit tests passed
  • Maven Dependency Plugin downstream check: 415 unit tests passed; 102 of 103
    Invoker projects passed. The remaining project asserts the previous scope
    recommendation and passes with the unpatched analyzer. Its dependency graph
    contains the exact condition fixed here: JUnit is also reachable through
    maven-project -> plexus-container-default.

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.

Build separate compile and runtime dependency graphs when identifying test-only dependencies. This avoids suggesting test scope when another non-test dependency still requires the candidate transitively.

Fixes apache/maven-dependency-plugin#1483
@wilx
wilx marked this pull request as ready for review August 1, 2026 23:01
@elharo elharo added the bug Something isn't working label Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MDEP-977] Incorrect handling if transitive compile dependency is used in tests

2 participants