Skip to content

fix incorrect ignored dependencies in verbose analyze output#1652

Open
elharo wants to merge 2 commits into
masterfrom
fix-1645
Open

fix incorrect ignored dependencies in verbose analyze output#1652
elharo wants to merge 2 commits into
masterfrom
fix-1645

Conversation

@elharo

@elharo elharo commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

dependency:analyze -Dverbose prints every dependency in both the warning section and the "Ignored" section when no ignoredDependencies are configured.

fixes #1645

Root cause

filterDependencies() returns the full input artifacts set when excludes is null or empty (line 563). The method is meant to return the artifacts that were excluded (matched an exclude pattern). When no patterns are given, nothing was excluded, so it should return an empty set. Returning the full set instead tells all 8 callers that "everything was excluded," filling the ignored sections with duplicates.

Fix

One-line change in AbstractAnalyzeMojo.java:563:

return new LinkedHashSet<>();

instead of:

return artifacts;

Integration test

Added mdep-1645-verbose-no-duplicate-ignored IT that:

  • Declares commons-text, uses commons-lang3 (transitive)
  • Runs dependency:analyze -Dverbose with no ignoredDependencies
  • Asserts the warning sections appear but the ignored sections do not

The test fails at HEAD and passes with the fix.

PR contains:

  • bug fix
  • integration test (fails on unpatched code)
  • no new unit test (the fix is a one-line change with no new logic)

@elharo elharo changed the title MDEP-1645: fix duplicated ignored dependencies in verbose analyze output fix duplicated ignored dependencies in verbose analyze output Jul 7, 2026
filterDependencies returns the full input set when excludes is null or
empty, telling callers that every artifact was excluded. This causes
all artifacts to appear in both the warning and ignored sections when
dependency:analyze -Dverbose runs with no ignoredDependencies configured.

Return an empty set instead when no exclude patterns are provided,
which correctly communicates that nothing was excluded.
@elharo elharo added the bug Something isn't working label Jul 7, 2026
@elharo elharo requested a review from slawekjaranowski July 7, 2026 12:22
@elharo elharo changed the title fix duplicated ignored dependencies in verbose analyze output fix incorrect ignored dependencies in verbose analyze output Jul 7, 2026
@elharo elharo self-assigned this Jul 7, 2026
@elharo elharo requested a review from Copilot July 7, 2026 12:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes incorrect dependency:analyze -Dverbose output where dependencies were erroneously reported under both warning sections and “Ignored …” sections when no ignored/exclude patterns are configured, by correcting the contract of filterDependencies() and adding an integration test to prevent regressions.

Changes:

  • Fix filterDependencies() to return an empty set (instead of the full input set) when no exclude patterns are provided.
  • Add a new IT project reproducing #1645 and verifying that “Ignored …” sections are not printed when nothing is configured to be ignored.
  • Improve in-code documentation for filterDependencies() with a clearer contract description.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java Corrects filterDependencies() behavior for null/empty excludes and documents the method contract.
src/it/projects/mdep-1645-verbose-no-duplicate-ignored/verify.groovy Verifies verbose analyze warnings appear and that “Ignored …” sections do not appear when not configured.
src/it/projects/mdep-1645-verbose-no-duplicate-ignored/src/main/java/test/App.java Provides bytecode usage of a transitive dependency to trigger “used undeclared” in analyze.
src/it/projects/mdep-1645-verbose-no-duplicate-ignored/pom.xml Declares commons-text and configures verbose output for the dependency plugin under test.
src/it/projects/mdep-1645-verbose-no-duplicate-ignored/invoker.properties Runs the dependency:analyze goal for the new IT project.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Add an assertion for a class line that only appears in verbose output for used-undeclared dependencies.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

filterDependencies returns the full input set when no excludes are configured, polluting verbose output

2 participants