You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2021/04/08 20:13:17 UTC
[maven-dependency-plugin] 01/02: MDEP-714 Add analyze parameter
"ignoreUnusedRuntime"
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch knickla/mdep-714/ignore-unused-runtime
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git
commit d5fd93a97d5d45c3ec41ee58efc5fe79ee1e6f55
Author: Lars Knickrehm <ma...@lars-sh.de>
AuthorDate: Sat Jan 2 15:38:16 2021 +0100
MDEP-714 Add analyze parameter "ignoreUnusedRuntime"
---
.../dependency/analyze/AbstractAnalyzeMojo.java | 23 ++++++++++++++++++++++
1 file changed, 23 insertions(+)
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 d32420c..315bb52 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
@@ -102,6 +102,12 @@ public abstract class AbstractAnalyzeMojo
private boolean ignoreNonCompile;
/**
+ * Ignore Runtime scope for unused dependency analysis.
+ */
+ @Parameter( property = "ignoreUnusedRuntime", defaultValue = "false" )
+ private boolean ignoreUnusedRuntime;
+
+ /**
* Output the xml for the missing dependencies (used but not declared).
*
* @since 2.0-alpha-5
@@ -323,6 +329,11 @@ public abstract class AbstractAnalyzeMojo
Set<Artifact> ignoredUsedUndeclared = new LinkedHashSet<>();
Set<Artifact> ignoredUnusedDeclared = new LinkedHashSet<>();
+
+ if ( ignoreUnusedRuntime )
+ {
+ filterUnusedByScope( unusedDeclared, Artifact.SCOPE_RUNTIME );
+ }
ignoredUsedUndeclared.addAll( filterDependencies( usedUndeclared, ignoredDependencies ) );
ignoredUsedUndeclared.addAll( filterDependencies( usedUndeclared, ignoredUsedUndeclaredDependencies ) );
@@ -402,6 +413,18 @@ public abstract class AbstractAnalyzeMojo
return warning;
}
+ private void filterUnusedByScope( Set<Artifact> unusedDeclared, String scope )
+ {
+ for ( Iterator<Artifact> iterator = unusedDeclared.iterator(); iterator.hasNext(); )
+ {
+ Artifact artifact = iterator.next();
+ if ( artifact.getScope().equals( scope ) )
+ {
+ iterator.remove();
+ }
+ }
+ }
+
private void logArtifacts( Set<Artifact> artifacts, boolean warn )
{
if ( artifacts.isEmpty() )