This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch fix-1645
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git

commit ad1bd76e7c1a15eae86cebf346fc325f74e0b3fa
Author: elharo <[email protected]>
AuthorDate: Tue Jul 7 12:02:21 2026 +0000

    MDEP-1645: fix duplicated ignored dependencies in verbose analyze output
    
    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.
---
 .../invoker.properties                             | 18 +++++++
 .../mdep-1645-verbose-no-duplicate-ignored/pom.xml | 61 ++++++++++++++++++++++
 .../src/main/java/test/App.java                    | 25 +++++++++
 .../verify.groovy                                  | 35 +++++++++++++
 .../dependency/analyze/AbstractAnalyzeMojo.java    |  2 +-
 5 files changed, 140 insertions(+), 1 deletion(-)

diff --git 
a/src/it/projects/mdep-1645-verbose-no-duplicate-ignored/invoker.properties 
b/src/it/projects/mdep-1645-verbose-no-duplicate-ignored/invoker.properties
new file mode 100644
index 00000000..4bbc5ed1
--- /dev/null
+++ b/src/it/projects/mdep-1645-verbose-no-duplicate-ignored/invoker.properties
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.goals = clean 
${project.groupId}:${project.artifactId}:${project.version}:analyze
diff --git a/src/it/projects/mdep-1645-verbose-no-duplicate-ignored/pom.xml 
b/src/it/projects/mdep-1645-verbose-no-duplicate-ignored/pom.xml
new file mode 100644
index 00000000..9c237911
--- /dev/null
+++ b/src/it/projects/mdep-1645-verbose-no-duplicate-ignored/pom.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.dependency</groupId>
+  <artifactId>mdep-1645</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <name>Test</name>
+  <description>
+    Test dependency:analyze -Dverbose does not duplicate entries in ignored 
section
+  </description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-text</artifactId>
+      <version>1.10.0</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <artifactId>maven-dependency-plugin</artifactId>
+          <version>@project.version@</version>
+          <configuration>
+            <verbose>true</verbose>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+</project>
diff --git 
a/src/it/projects/mdep-1645-verbose-no-duplicate-ignored/src/main/java/test/App.java
 
b/src/it/projects/mdep-1645-verbose-no-duplicate-ignored/src/main/java/test/App.java
new file mode 100644
index 00000000..4d20ae36
--- /dev/null
+++ 
b/src/it/projects/mdep-1645-verbose-no-duplicate-ignored/src/main/java/test/App.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package test;
+import org.apache.commons.lang3.StringUtils;
+public class App {
+    public void test() {
+        System.out.println(StringUtils.capitalize("hello"));
+    }
+}
diff --git 
a/src/it/projects/mdep-1645-verbose-no-duplicate-ignored/verify.groovy 
b/src/it/projects/mdep-1645-verbose-no-duplicate-ignored/verify.groovy
new file mode 100644
index 00000000..f308fc2a
--- /dev/null
+++ b/src/it/projects/mdep-1645-verbose-no-duplicate-ignored/verify.groovy
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+File buildLog = new File( basedir, "build.log" )
+assert buildLog.exists()
+
+String log = buildLog.getText( "UTF-8" )
+
+// warning sections should be present
+assert log.contains( '[WARNING] Used undeclared dependencies found:' )
+assert log.contains( '[WARNING]    
org.apache.commons:commons-lang3:jar:3.12.0:compile' )
+assert log.contains( '[WARNING] Unused declared dependencies found:' )
+assert log.contains( '[WARNING]    
org.apache.commons:commons-text:jar:1.10.0:compile' )
+
+// when no ignoredDependencies are configured, the ignored sections should not 
appear
+assert !log.contains( 'Ignored used undeclared dependencies' )
+assert !log.contains( 'Ignored unused declared dependencies' )
+
+return true
diff --git 
a/src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java
 
b/src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java
index 56324c0a..d0c34c1b 100644
--- 
a/src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java
+++ 
b/src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java
@@ -560,7 +560,7 @@ public abstract class AbstractAnalyzeMojo extends 
AbstractMojo {
 
     private Set<Artifact> filterDependencies(Set<Artifact> artifacts, String[] 
excludes) {
         if (excludes == null || excludes.length == 0) {
-            return artifacts;
+            return new LinkedHashSet<>();
         }
         ArtifactFilter filter = new 
StrictPatternExcludesArtifactFilter(Arrays.asList(excludes));
         Set<Artifact> result = new LinkedHashSet<>();

Reply via email to