diff --git a/pom.xml b/pom.xml index c925acd6f..dc4c14af1 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ under the License. maven-dependency-plugin - 3.2.1-disy-1 + 3.2.1-disy-2 maven-plugin Apache Maven Dependency Plugin 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 64cb59f78..24ef62c1f 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 @@ -228,6 +228,9 @@ public abstract class AbstractAnalyzeMojo @Parameter private String[] ignoredUnusedDeclaredDependencies = new String[0]; + @Parameter + private String[] ignoredCompileScopedUsedOnlyInTestsDependencies = new String[0]; + /** * List of project packaging that will be ignored. *
@@ -359,6 +362,8 @@ private boolean checkDependencies() ignoredUnusedDeclared.addAll( filterDependencies( unusedDeclared, ignoredDependencies ) ); ignoredUnusedDeclared.addAll( filterDependencies( unusedDeclared, ignoredUnusedDeclaredDependencies ) ); + filterDependencies( testArtifactsWithNonTestScope, ignoredCompileScopedUsedOnlyInTestsDependencies ); + boolean reported = false; boolean warning = false; @@ -420,7 +425,7 @@ private boolean checkDependencies() if ( outputJSON ) { - writeDependencyJSON( usedUndeclared, unusedDeclared ); + writeDependencyJSON( usedUndeclared, unusedDeclared, testArtifactsWithNonTestScope ); } if ( scriptableOutput ) @@ -526,9 +531,13 @@ private String joinArtifacts( List artifacts ) return sb.toString(); } - private void writeDependencyJSON( Set usedUndeclared, Set unusedDeclared ) + private void writeDependencyJSON( + Set usedUndeclared, + Set unusedDeclared, + Set testArtifactsWithNonTestScope + ) { - if ( !usedUndeclared.isEmpty() || !unusedDeclared.isEmpty() ) + if ( !usedUndeclared.isEmpty() || !unusedDeclared.isEmpty() || !testArtifactsWithNonTestScope.isEmpty() ) { StringBuilder buf = new StringBuilder(); @@ -550,6 +559,16 @@ private void writeDependencyJSON( Set usedUndeclared, Set un buf.append( joinArtifacts( new ArrayList<>( unusedDeclared ) ) ); buf.append( "]" ); } + if ( !testArtifactsWithNonTestScope.isEmpty() ) + { + if ( !usedUndeclared.isEmpty() || !unusedDeclared.isEmpty() ) + { + buf.append( ", " ); + } + buf.append( "testOnlyWithNonTestScope: [" ); + buf.append( joinArtifacts( new ArrayList<>( testArtifactsWithNonTestScope ) ) ); + buf.append( "]" ); + } buf.append( "}" ); getLog().warn( buf.toString() ); }