diff --git a/src/it/projects/analyze-ignore-dependency/pom.xml b/src/it/projects/analyze-ignore-dependency/pom.xml index bc43ff5cc..c802f08e5 100644 --- a/src/it/projects/analyze-ignore-dependency/pom.xml +++ b/src/it/projects/analyze-ignore-dependency/pom.xml @@ -55,6 +55,7 @@ org.apache.maven:maven-project org.apache.maven:maven-model + org.apache.maven:maven-settings diff --git a/src/it/projects/analyze-ignore-dependency/src/test/java/MainTest.java b/src/it/projects/analyze-ignore-dependency/src/test/java/MainTest.java new file mode 100644 index 000000000..911d74d75 --- /dev/null +++ b/src/it/projects/analyze-ignore-dependency/src/test/java/MainTest.java @@ -0,0 +1,29 @@ +/* + * 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. + */ + +import org.apache.maven.settings.Settings; + +public class MainTest +{ + public Settings settings = null; + + public void testPass() + { + } +} diff --git a/src/it/projects/analyze-ignore-non-test-scope-dependency/invoker.properties b/src/it/projects/analyze-ignore-non-test-scope-dependency/invoker.properties new file mode 100644 index 000000000..e60283028 --- /dev/null +++ b/src/it/projects/analyze-ignore-non-test-scope-dependency/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/analyze-ignore-non-test-scope-dependency/pom.xml b/src/it/projects/analyze-ignore-non-test-scope-dependency/pom.xml new file mode 100644 index 000000000..34cb9fed0 --- /dev/null +++ b/src/it/projects/analyze-ignore-non-test-scope-dependency/pom.xml @@ -0,0 +1,63 @@ + + + + + 4.0.0 + + org.apache.maven.its.dependency + test + 1.0-SNAPSHOT + + Test + + Test dependency:analyze with ignoredNonTestScopedDependencies + + + + UTF-8 + + + + + org.apache.maven + maven-settings + @mavenVersion@ + + + + + + + + maven-dependency-plugin + + true + true + + org.apache.maven:maven-settings + + + + + + + diff --git a/src/it/projects/analyze-ignore-non-test-scope-dependency/src/test/java/MainTest.java b/src/it/projects/analyze-ignore-non-test-scope-dependency/src/test/java/MainTest.java new file mode 100644 index 000000000..911d74d75 --- /dev/null +++ b/src/it/projects/analyze-ignore-non-test-scope-dependency/src/test/java/MainTest.java @@ -0,0 +1,29 @@ +/* + * 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. + */ + +import org.apache.maven.settings.Settings; + +public class MainTest +{ + public Settings settings = null; + + public void testPass() + { + } +} 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 860135565..23c58f210 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 @@ -223,6 +223,26 @@ public abstract class AbstractAnalyzeMojo @Parameter private String[] ignoredUnusedDeclaredDependencies = new String[0]; + /** + * List of dependencies that will be ignored if they are in not test scope but are only used in test classes. + * The filter syntax is: + * + *
+     * [groupId]:[artifactId]:[type]:[version]
+     * 
+ * + * where each pattern segment is optional and supports full and partial * wildcards. An empty pattern + * segment is treated as an implicit wildcard. * + *

+ * For example, org.apache.* will match all artifacts whose group id starts with + * org.apache., and :::*-SNAPSHOT will match all snapshot artifacts. + *

+ * + * @since 3.3.0 + */ + @Parameter + private String[] ignoredNonTestScopedDependencies = new String[0]; + /** * List of project packaging that will be ignored. *
@@ -332,11 +352,11 @@ private boolean checkDependencies() Map> usedUndeclaredWithClasses = new LinkedHashMap<>( analysis.getUsedUndeclaredArtifactsWithClasses() ); Set unusedDeclared = new LinkedHashSet<>( analysis.getUnusedDeclaredArtifacts() ); - Set testArtifactsWithNonTestScope = new LinkedHashSet<>( - analysis.getTestArtifactsWithNonTestScope() ); + Set nonTestScope = new LinkedHashSet<>( analysis.getTestArtifactsWithNonTestScope() ); Set ignoredUsedUndeclared = new LinkedHashSet<>(); Set ignoredUnusedDeclared = new LinkedHashSet<>(); + Set ignoredNonTestScope = new LinkedHashSet<>(); if ( ignoreUnusedRuntime ) { @@ -350,6 +370,9 @@ private boolean checkDependencies() ignoredUnusedDeclared.addAll( filterDependencies( unusedDeclared, ignoredDependencies ) ); ignoredUnusedDeclared.addAll( filterDependencies( unusedDeclared, ignoredUnusedDeclaredDependencies ) ); + ignoredNonTestScope.addAll( filterDependencies( nonTestScope, ignoredDependencies ) ); + ignoredNonTestScope.addAll( filterDependencies( nonTestScope, ignoredNonTestScopedDependencies ) ); + boolean reported = false; boolean warning = false; @@ -386,11 +409,11 @@ private boolean checkDependencies() warning = true; } - if ( !testArtifactsWithNonTestScope.isEmpty() ) + if ( !nonTestScope.isEmpty() ) { getLog().warn( "Non-test scoped test only dependencies found:" ); - logArtifacts( testArtifactsWithNonTestScope, true ); + logArtifacts( nonTestScope, true ); reported = true; warning = true; } @@ -411,6 +434,14 @@ private boolean checkDependencies() reported = true; } + if ( verbose && !ignoredNonTestScope.isEmpty() ) + { + getLog().info( "Ignored non-test scoped test only dependencies:" ); + + logArtifacts( ignoredNonTestScope, false ); + reported = true; + } + if ( outputXML ) { writeDependencyXML( usedUndeclaredWithClasses.keySet() );