maven dependency plugin throwing error even if I add flag ignoreunuseddeclareddependecy

Viewed 275

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.

2 Answers

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

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

Related