java - 抑制 Maven 依赖插件的 "Unused declared dependencies found"警告

标签 java maven maven-3 pom.xml maven-dependency-plugin

maven-dependency-plugin通过在编译时产生警告来识别它认为是未使用的依赖项。

[WARNING] Unused declared dependencies found:
[WARNING]    org.foo:bar-api:jar:1.7.5:compile

在某些情况下,此消息是误报,并且依赖关系是可传递的。

问题:如何在我的 pom.xml 中识别出这种情况?

最佳答案

您应该在 pom 中配置 ignoredDependencies元素:

List of dependencies that will be ignored. Any dependency on this list will be excluded from the "declared but unused" and the "used but undeclared" list. 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. *

也是官方指定的Exclude dependencies from dependency analysis . 示例配置为:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.10</version>
            <executions>
                <execution>
                    <id>analyze-dep</id>
                    <goals>
                        <goal>analyze-only</goal>
                    </goals>
                    <configuration>
                        <ignoredDependencies>
                            <ignoredDependency>org.foo:bar-api:jar:1.7.5</ignoredDependency>
                        </ignoredDependencies>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

关于java - 抑制 Maven 依赖插件的 "Unused declared dependencies found"警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36573510/

相关文章:

java - 为 StringTokenizer 中的空内容赋值

java - 如何在java中将字符串拆分为数字和字母

java - 使用 Maven 构建项目和将 Eclipse 导出为 Jar 之间的区别

Java的Maven工具,如何使用mvn uninstall package?

java - Unresolved org.codehaus.mojo :sonar-maven-plugin:3. 0.1 Intellij - Maven 项目

maven - 如何在项目中生成jar和war

java - 内容解析器 - 添加新的非本地日历 - 进程结束时删除日历

java - 单例模式在多线程环境中有什么问题吗?

java - Junit4 和 TestNG 位于一个带有 Maven 继承的项目中

Netbeans 中的 Maven 项目 : How to add dependency to both 'Dependencies' and 'Test Dependencies' ?