1

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 Answers2

0

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

slindenau
  • 1,091
  • 2
  • 11
  • 18
  • I am using maven dependency plugin v 3.1.1, and the settings I have are right , but I still get the warning and the build is failing! Only the code builded successfully when I add this ` com:test-client ` – ethicalhacker May 25 '22 at 11:14
  • @ethicalhacker What happens if you configure is as `com:test-client` ? Can you confirm the plugin version used in the output log? For me it's for example `[INFO] --- maven-dependency-plugin:3.3.0:analyze` – slindenau May 25 '22 at 11:22
  • nothing happens I already tried this the buil is still failing. As for the version now I just noticed that in the output the version is 2.10 however, in the pom the version is declared asa 3.1.1 output: `[INFO] --- maven-dependency-plugin:2.10:analyze-only (analyze) @ MyTest ---` – ethicalhacker May 25 '22 at 11:40
  • @ethicalhacker that might be causing some issues, check with `mvn help:effective-pom` how the plugin is configured. Maybe you're running a different plugin/project than you're expecting. The configuration you have should be valid for `3.1.1`. How are you running this build or the plugin, any specifics on that configuration you can add? Part of the `verify` stage in maven? – slindenau May 25 '22 at 11:49
  • when I'm running mvn help:effective-pom I am getting errors. How I'm running the build? from intellij I'm clicking on the install in the lifecycle – ethicalhacker May 25 '22 at 13:07
  • @ethicalhacker ok the install lifecycle also executes verify, which runs the dependency:analyze. That is good. I suggest you try to fix the POM errors first. You can also include a specific version for the dependency-plugin in your plugin definition in the pom, does that change the output? – slindenau May 25 '22 at 13:10
  • the plugin version is already included in my pom: ` org.apache.maven.plugins maven-dependency-plugin 3.1.1 ` – ethicalhacker May 25 '22 at 13:23
  • @ethicalhacker since that doesn't seem to work, and your effective pom is getting errors, i suggest you start fixing those. There is probably something else wrong with your pom. If you solve that, this problem with the dependency plugin will probably be fixed as well. I confirmed on my test project that similar ignore settings work. – slindenau May 25 '22 at 14:06
  • This is the error I'm getting when running `mvn help:effective-pom` `[ERROR] [ERROR] Some problems were encountered while processing the POMs: [ERROR] Unresolveable build extension: Plugin murex.maven.plugins.download.generator:download-generator-extension:1.8.0 or one of its dependencies could not be resolved: ` – ethicalhacker May 25 '22 at 14:30
  • `murex.maven.plugins.download.generator:download-generator-exte nsion:jar:1.8.0 was not found in https://repo.maven.apache.org/maven2 during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of central has elapsed or u pdates are forced @ @ ` – ethicalhacker May 25 '22 at 14:30
  • `[ERROR] The build could not read 1 project -> [Help 1] [ERROR] [ERROR] The project xxx:MyTest:V1.0-SNAPSHOT (C:\path\to\mytest\security-tests\pom.xml) has 1 error [ERROR] Unresolveable build extension: Plugin murex.maven.plugins.download.generator:download-generator-extension:1.8.0 or one of its dependencies could not be resolved: ` – ethicalhacker May 25 '22 at 14:31
  • `murex.maven.plugins.download.generator:download-generator- extension:jar:1.8.0 was not found in https://repo.maven.apache.org/maven2 during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of central has elapsed or updates are forced -> [Help 2]` – ethicalhacker May 25 '22 at 14:31
  • @ethicalhacker that is a different error than this question, please review the answers you've received on other questions how to resolve maven dependency & repository issues. If you have enough reputation to join a chat room we can perhaps have a look, as this discussion is getting too long (requirement: 20 rep). – slindenau May 25 '22 at 14:34
  • Unfortunatley I have only 5 rep so I think I can't join a chat. I will try to search online but note that I ma working in a multi module project, so my pom is a child of other pom. – ethicalhacker May 25 '22 at 15:33
  • hello, 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. – ethicalhacker May 26 '22 at 15:49
  • @ethicalhacker glad you got it working! I think that parent/child configuration and execution stages is a different topic. You can research it and ask a new question if you get stuck. – slindenau Jun 01 '22 at 17:13
  • thank you! is there a way to highlight my comment as the solution? – ethicalhacker Jun 02 '22 at 08:08
  • @ethicalhacker no you would have to [answer your own question](https://stackoverflow.com/help/self-answer) – slindenau Jun 02 '22 at 08:11
0

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