You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2022/02/12 15:03:51 UTC
[maven-dependency-plugin] 01/01: [MDEP-787] allow ignoring non-test-scoped dependencies
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch MDEP-787
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git
commit 25d0d98cc9269393b0f12a596c5e97637efde9aa
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Sat Feb 12 16:03:12 2022 +0100
[MDEP-787] allow ignoring non-test-scoped dependencies
---
src/it/projects/analyze-ignore-dependency/pom.xml | 1 +
.../src/test/java/MainTest.java | 29 ++++++++++++++++
.../invoker.properties | 18 ++++++++++
.../pom.xml | 13 ++++----
.../src/test/java/MainTest.java | 29 ++++++++++++++++
.../dependency/analyze/AbstractAnalyzeMojo.java | 39 +++++++++++++++++++---
6 files changed, 118 insertions(+), 11 deletions(-)
diff --git a/src/it/projects/analyze-ignore-dependency/pom.xml b/src/it/projects/analyze-ignore-dependency/pom.xml
index bc43ff5..c802f08 100644
--- a/src/it/projects/analyze-ignore-dependency/pom.xml
+++ b/src/it/projects/analyze-ignore-dependency/pom.xml
@@ -55,6 +55,7 @@
<ignoredDependencies>
<ignoredDependency>org.apache.maven:maven-project</ignoredDependency>
<ignoredDependency>org.apache.maven:maven-model</ignoredDependency>
+ <ignoredDependency>org.apache.maven:maven-settings</ignoredDependency>
</ignoredDependencies>
</configuration>
</plugin>
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 0000000..911d74d
--- /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 0000000..e602830
--- /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-dependency/pom.xml b/src/it/projects/analyze-ignore-non-test-scope-dependency/pom.xml
similarity index 83%
copy from src/it/projects/analyze-ignore-dependency/pom.xml
copy to src/it/projects/analyze-ignore-non-test-scope-dependency/pom.xml
index bc43ff5..34cb9fe 100644
--- a/src/it/projects/analyze-ignore-dependency/pom.xml
+++ b/src/it/projects/analyze-ignore-non-test-scope-dependency/pom.xml
@@ -29,7 +29,7 @@
<name>Test</name>
<description>
- Test dependency:analyze with ignoreDependencies
+ Test dependency:analyze with ignoredNonTestScopedDependencies
</description>
<properties>
@@ -39,8 +39,8 @@
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
- <artifactId>maven-project</artifactId>
- <version>2.0.6</version>
+ <artifactId>maven-settings</artifactId>
+ <version>@mavenVersion@</version>
</dependency>
</dependencies>
@@ -52,10 +52,9 @@
<configuration>
<verbose>true</verbose>
<failOnWarning>true</failOnWarning>
- <ignoredDependencies>
- <ignoredDependency>org.apache.maven:maven-project</ignoredDependency>
- <ignoredDependency>org.apache.maven:maven-model</ignoredDependency>
- </ignoredDependencies>
+ <ignoredNonTestScopedDependencies>
+ <ignoredNonTestScopedDependency>org.apache.maven:maven-settings</ignoredNonTestScopedDependency>
+ </ignoredNonTestScopedDependencies>
</configuration>
</plugin>
</plugins>
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 0000000..911d74d
--- /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 8601355..c6c6afe 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
@@ -224,6 +224,26 @@ public abstract class AbstractAnalyzeMojo
private String[] ignoredUnusedDeclaredDependencies = new String[0];
/**
+ * List of dependencies that will be ignored if they are in compile scope but only used in test classes.
+ * The filter syntax is:
+ *
+ * <pre>
+ * [groupId]:[artifactId]:[type]:[version]
+ * </pre>
+ *
+ * where each pattern segment is optional and supports full and partial <code>*</code> wildcards. An empty pattern
+ * segment is treated as an implicit wildcard. *
+ * <p>
+ * For example, <code>org.apache.*</code> will match all artifacts whose group id starts with
+ * <code>org.apache.</code>, and <code>:::*-SNAPSHOT</code> will match all snapshot artifacts.
+ * </p>
+ *
+ * @since 3.3.0
+ */
+ @Parameter
+ private String[] ignoredNonTestScopedDependencies = new String[0];
+
+ /**
* List of project packaging that will be ignored.
* <br/>
* <b>Default value is<b>: <code>pom, ear</code>
@@ -332,11 +352,11 @@ public abstract class AbstractAnalyzeMojo
Map<Artifact, Set<String>> usedUndeclaredWithClasses =
new LinkedHashMap<>( analysis.getUsedUndeclaredArtifactsWithClasses() );
Set<Artifact> unusedDeclared = new LinkedHashSet<>( analysis.getUnusedDeclaredArtifacts() );
- Set<Artifact> testArtifactsWithNonTestScope = new LinkedHashSet<>(
- analysis.getTestArtifactsWithNonTestScope() );
+ Set<Artifact> nonTestScope = new LinkedHashSet<>( analysis.getTestArtifactsWithNonTestScope() );
Set<Artifact> ignoredUsedUndeclared = new LinkedHashSet<>();
Set<Artifact> ignoredUnusedDeclared = new LinkedHashSet<>();
+ Set<Artifact> ignoredNonTestScope = new LinkedHashSet<>();
if ( ignoreUnusedRuntime )
{
@@ -350,6 +370,9 @@ public abstract class AbstractAnalyzeMojo
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 @@ public abstract class AbstractAnalyzeMojo
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 @@ public abstract class AbstractAnalyzeMojo
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() );