Maven依赖插件抛出错误,即使我添加flag imageunusedDeclaredDependecyecy

发布于 2025-02-01 15:26:12 字数 1838 浏览 7 评论 0 原文

我正在尝试构建我的代码,并且会遇到此错误:

[WARNING] Unused declared dependencies found:
[WARNING]    com:test-client:jar:v1.0-SNAPSHOT:compile

这是我的POM中依赖关系插件的配置:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>analyze</id>
                        <goals>
                            <goal>analyze-only</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
<!--                    <usedDependencies>-->
<!--                        <usedDependency>com:test-client</usedDependency>-->
<!--                    </usedDependencies>-->
                    <failOnWarning>true</failOnWarning>
                    <ignoreNonCompile>true</ignoreNonCompile>
                    <ignoredUnusedDeclaredDependencies>
<!--                        <ignoredUnusedDeclaredDependency>*:test-client:*</ignoredUnusedDeclaredDependency>-->
                    </ignoredUnusedDeclaredDependencies>
                </configuration>
            </plugin>

我试图将测试客户添加到FLAG忽略的trag-nunsedDeclaredDippedecy中(请参阅注释的部分),但仍会遇到错误。

我试图将FailOnwarning Flag设置为False,但也会得到同样的警告。

当我添加本节时,它可以正常工作。

<usedDependencies>
                        <usedDependency>com:test-client</usedDependency>
                    </usedDependencies> 

但是,为什么没有采取其他两个旗帜呢?

请注意,我正在一个多模块项目中工作,这是父型POM的孩子。

I am trying to build my code and I am getting this error:

[WARNING] Unused declared dependencies found:
[WARNING]    com:test-client:jar:v1.0-SNAPSHOT:compile

This is the configuration of the dependency plugin in my pom:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>analyze</id>
                        <goals>
                            <goal>analyze-only</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
<!--                    <usedDependencies>-->
<!--                        <usedDependency>com:test-client</usedDependency>-->
<!--                    </usedDependencies>-->
                    <failOnWarning>true</failOnWarning>
                    <ignoreNonCompile>true</ignoreNonCompile>
                    <ignoredUnusedDeclaredDependencies>
<!--                        <ignoredUnusedDeclaredDependency>*:test-client:*</ignoredUnusedDeclaredDependency>-->
                    </ignoredUnusedDeclaredDependencies>
                </configuration>
            </plugin>

I tried to add the test-client to the flag ignoredUnsedDeclaredDependecy (see the commented part) but still getting error.

I tried to set the failOnWarning flag to false but also I get same warning.

When I added this section it works.

<usedDependencies>
                        <usedDependency>com:test-client</usedDependency>
                    </usedDependencies> 

But why the 2 other flags are not being taken?

Note that I am working in a multi module project and this is a child pom of a parent pom.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独行侠 2025-02-08 15:26:12

failonwarning 使Maven构建失败如果发出警告,则不会删除或阻止警告。参见

关于Exluseions的配置,请参见

提供了类似的例子;

<configuration>
  <failOnWarning>true</failOnWarning>

  <!-- ignore jsr305 for "used but undeclared", "declared but unused", and "non-test scoped" -->
  <ignoredDependencies>
    <ignoredDependency>com.google.code.findbugs:jsr305</ignoredDependency>
  </ignoredDependencies>

  <!-- ignore annotations for "used but undeclared" warnings -->
  <ignoredUsedUndeclaredDependencies>
    <ignoredUsedUndeclaredDependency>com.google.code.findbugs:annotations</ignoredUsedUndeclaredDependency>
  </ignoredUsedUndeclaredDependencies>

  <!-- ignore annotations for "unused but declared" warnings -->
  <ignoredUnusedDeclaredDependencies>
    <ignoredUnusedDeclaredDependency>com.google.code.findbugs:annotations</ignoredUnusedDeclaredDependency>
  </ignoredUnusedDeclaredDependencies>

  <!-- ignore annotations for "non-test scoped" warnings -->
  <ignoredNonTestScopedDependencies>
    <ignoredNonTestScopedDependency>com.google.code.findbugs:annotations</ignoredNonTestScopedDependency>
  </ignoredNonTestScopedDependencies>
</configuration>

因此,您的语法应该是正确的。
您是否依赖最新版本的插件?如果没有,请尝试将版本编号更新为最新的版本,您可以访问: https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-depperency-plugin
忽略了declaredDepentencies 在插件版本 2.10 忽略nontestscopedDepentencies 以来,因为 3.3.0

还要根据 https://maven.apache.org/plugins/maven-depparency-plugin/examples/filtering-the-deplyency-tree.html

failOnWarning makes the maven build fail if a warning was generated, it doesn't remove or prevent the warnings. See https://maven.apache.org/plugins/maven-dependency-plugin/examples/failing-the-build-on-dependency-analysis-warnings.html

Regarding the configuration of exlusions, see https://maven.apache.org/plugins/maven-dependency-plugin/examples/exclude-dependencies-from-dependency-analysis.html

That gives an example like so;

<configuration>
  <failOnWarning>true</failOnWarning>

  <!-- ignore jsr305 for "used but undeclared", "declared but unused", and "non-test scoped" -->
  <ignoredDependencies>
    <ignoredDependency>com.google.code.findbugs:jsr305</ignoredDependency>
  </ignoredDependencies>

  <!-- ignore annotations for "used but undeclared" warnings -->
  <ignoredUsedUndeclaredDependencies>
    <ignoredUsedUndeclaredDependency>com.google.code.findbugs:annotations</ignoredUsedUndeclaredDependency>
  </ignoredUsedUndeclaredDependencies>

  <!-- ignore annotations for "unused but declared" warnings -->
  <ignoredUnusedDeclaredDependencies>
    <ignoredUnusedDeclaredDependency>com.google.code.findbugs:annotations</ignoredUnusedDeclaredDependency>
  </ignoredUnusedDeclaredDependencies>

  <!-- ignore annotations for "non-test scoped" warnings -->
  <ignoredNonTestScopedDependencies>
    <ignoredNonTestScopedDependency>com.google.code.findbugs:annotations</ignoredNonTestScopedDependency>
  </ignoredNonTestScopedDependencies>
</configuration>

So your syntax should be correct.
Do you depend on the latest version of the plugin? If not, try to update the version number to the most recent one you have access to: https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-dependency-plugin
ignoredUnusedDeclaredDependencies was added in the plugin version 2.10 and ignoredNonTestScopedDependencies since 3.3.0.

Also check if your wildcard filter syntax is correct according to https://maven.apache.org/plugins/maven-dependency-plugin/examples/filtering-the-dependency-tree.html

↘人皮目录ツ 2025-02-08 15:26:12

我想出了什么问题!我的设置被父母POM所覆盖,为什么呢?因为在父pom中,配置是在执行下编写的,但是在我的pom中,当我在执行下移动插件中的配置时,配置在执行外部执行(直接在插件下),我的设置被考虑在考虑

I figured out what was the issue! my settings were override by the parent pom, why so? because in the parent pom the configuration is written under execution, however in my pom the configuration is outside execution (directly under plugin) when I moved the configuration in my plugin under the execution, my settings were taken into consideration

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文