1

I have a Maven module (part of a multi-module project) with the following dependency declared:

<dependency>
  <groupId>commons-logging</groupId>
  <artifactId>commons-logging</artifactId>
  <version>1.1</version>
</dependency>

Classes from that package are used in the following way:

private static final Log LOG = LogFactory.getLog(MyClass.class);

Everything compiles fine.

When I run mvn dependency:analyze (or analyze-only), the following warning is issued though:

[WARNING] Unused declared dependencies found:
[WARNING]    commons-logging:commons-logging:jar:1.1:compile

This seems to indicated that I could remove the said dependency, in particular because we want to set the failOnWarning option to true, the warning hence results in a build failure. However, the package is clearly required and when I remove it, the module fails to compile:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project mymodule: Compilation failure: Compilation failure:
[ERROR] MyClass.java:[18,34] package org.apache.commons.logging does not exist
[ERROR] MyClass.java:[19,34] package org.apache.commons.logging does not exist
[ERROR] MyClass.java:[44,26] cannot find symbol
[ERROR] symbol:   class Log
[ERROR] location: class MyClass

There are related questions around:

Why were Spring Boot starter dependencies designed to be used contrary to the stated intent of Maven's transitive dependency mechanisms?,

How to tell maven-dependency-plugin that the artifact is used in the project?,

Why is dependency:analyze lying to me?

but they are either unanswered or the answers relate to problems with scope. In my case, the scope needs to be compile (i.e. no need to declare).

Andrejs
  • 10,803
  • 4
  • 43
  • 48
Carsten
  • 1,912
  • 1
  • 28
  • 55
  • Which version of maven-dependency-plugin do you use? – khmarbaise Sep 14 '16 at 11:14
  • You might use an other version from a transitive dependency...recheck with `mvn dependency:tree` and see if commons-logging is coming from another dependency...or an other module? – khmarbaise Sep 14 '16 at 11:17
  • `maven-dependency-plugin` version is 2.10. There is indeed a transitive dependency on commons-logging in the tree, but with scope `test`. So it is not accessible on compile time. – Carsten Sep 14 '16 at 11:25
  • Also, the transitive dependency on commons-logging is the same version: `[INFO] | | +- commons-logging:commons-logging-api:jar:1.1:test`. – Carsten Sep 14 '16 at 11:32
  • I just noticed that these are actually two different dependencies (the transitive one being `-api`. However, when I change the explicit dependency to `-api`, the project still compiles, but the warning persists. – Carsten Sep 14 '16 at 12:26
  • Have you tried setting `ignoreNonCompile` for the plugin? (this allows not to modify the scope of the actual dependency) – Andrejs Dec 17 '17 at 18:03

0 Answers0