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:
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).