You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by he...@apache.org on 2022/05/09 20:24:00 UTC

[maven-dependency-plugin] branch master updated: [MDEP-804] - Allow auto-ignore of all non-test scoped dependencies used only in test scope (#211)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 73c59254 [MDEP-804] - Allow auto-ignore of all non-test scoped dependencies used only in test scope (#211)
73c59254 is described below

commit 73c59254252a404a699e6862ec71710174f31614
Author: Henning Schmiedehausen <he...@schmiedehausen.org>
AuthorDate: Mon May 9 13:23:56 2022 -0700

    [MDEP-804] - Allow auto-ignore of all non-test scoped dependencies used only in test scope (#211)
    
    Implements a flag that allows ignoring non-test scoped dependencies
    when they are used only in test scope.
    
    Includes integration test that verifies the behavior.
---
 .../invoker.properties                             | 18 +++++++
 .../pom.xml                                        | 61 ++++++++++++++++++++++
 .../src/test/java/MainTest.java                    | 29 ++++++++++
 .../dependency/analyze/AbstractAnalyzeMojo.java    | 22 +++++++-
 4 files changed, 128 insertions(+), 2 deletions(-)

diff --git a/src/it/projects/analyze-ignore-all-non-test-scope-dependency/invoker.properties b/src/it/projects/analyze-ignore-all-non-test-scope-dependency/invoker.properties
new file mode 100644
index 00000000..e6028302
--- /dev/null
+++ b/src/it/projects/analyze-ignore-all-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-all-non-test-scope-dependency/pom.xml b/src/it/projects/analyze-ignore-all-non-test-scope-dependency/pom.xml
new file mode 100644
index 00000000..a762b0b6
--- /dev/null
+++ b/src/it/projects/analyze-ignore-all-non-test-scope-dependency/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>test</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <name>Test</name>
+  <description>
+    Test dependency:analyze with ignoreAllNonTestScoped
+  </description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-settings</artifactId>
+      <version>@mavenVersion@</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <artifactId>maven-dependency-plugin</artifactId>
+          <configuration>
+           <verbose>true</verbose>
+           <failOnWarning>true</failOnWarning>
+           <ignoreAllNonTestScoped>true</ignoreAllNonTestScoped>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+</project>
diff --git a/src/it/projects/analyze-ignore-all-non-test-scope-dependency/src/test/java/MainTest.java b/src/it/projects/analyze-ignore-all-non-test-scope-dependency/src/test/java/MainTest.java
new file mode 100644
index 00000000..911d74d7
--- /dev/null
+++ b/src/it/projects/analyze-ignore-all-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 41d853f3..384bb965 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
@@ -110,6 +110,17 @@ public abstract class AbstractAnalyzeMojo
     @Parameter( property = "ignoreUnusedRuntime", defaultValue = "false" )
     private boolean ignoreUnusedRuntime;
 
+    /**
+     * Ignore all dependencies that are used only in test but not test-scoped. Setting
+     * this flag has the same effect as adding all dependencies that have been flagged with
+     * the <i>Non-test scoped test only dependencies found</i> warning to the
+     * <code>&lt;ignoredNonTestScopedDependencies&gt;</code> configuration.
+     *
+     * @since 3.3.1-SNAPSHOT
+     */
+    @Parameter( property = "ignoreAllNonTestScoped", defaultValue = "false" )
+    private boolean ignoreAllNonTestScoped;
+
     /**
      * Output the xml for the missing dependencies (used but not declared).
      *
@@ -372,8 +383,15 @@ public abstract class AbstractAnalyzeMojo
         ignoredUnusedDeclared.addAll( filterDependencies( unusedDeclared, ignoredDependencies ) );
         ignoredUnusedDeclared.addAll( filterDependencies( unusedDeclared, ignoredUnusedDeclaredDependencies ) );
 
-        ignoredNonTestScope.addAll( filterDependencies( nonTestScope, ignoredDependencies ) );
-        ignoredNonTestScope.addAll( filterDependencies( nonTestScope, ignoredNonTestScopedDependencies ) );
+        if ( ignoreAllNonTestScoped )
+        {
+            ignoredNonTestScope.addAll( filterDependencies ( nonTestScope, new String [] { "*" } ) );
+        }
+        else
+        {
+            ignoredNonTestScope.addAll( filterDependencies( nonTestScope, ignoredDependencies ) );
+            ignoredNonTestScope.addAll( filterDependencies( nonTestScope, ignoredNonTestScopedDependencies ) );
+        }
 
         boolean reported = false;
         boolean warning = false;