8

This is a structure of my multi-module project:

/root
  /api dependencies: slf4j
  /foo dependencies: slf4j-log4j12, log4j

In other words, module api uses slf4j for logging purposes. It doesn't know what the implementation of logging facility will be. Module foo adds slf4j-log4j12 and log4j in order to implement the logging. Pretty simple.

Now I'm running maven-dependency-plugin:analyze-only and this is what it says for module foo:

[WARNING] Unused declared dependencies found:
[WARNING]    org.slf4j:slf4j-log4j12:jar:1.6.1:compile
[WARNING]    log4j:log4j:jar:1.2.16:compile

Meaning that the plugin doesn't understand that foo really needs these dependencies. How can I solve the problem?

yegor256
  • 102,010
  • 123
  • 446
  • 597

2 Answers2

11

What happens if you give those dependencies a runtime scope instead of compile?

If you've defined them as compile-time dependencies I think the dependency plugin will think they are needed for the compile when they're really not. But you only need the slf4-log4j and log4j JAR files at runtime.

Edit: You may need to set the ignoreNonCompile option:

http://maven.apache.org/plugins/maven-dependency-plugin/analyze-mojo.html

  • Good idea, but the result is the same :( – yegor256 Feb 07 '11 at 09:09
  • 1
    @yegor256 I've just edited my answer. There is an 'ignoreNonCompile' flag on the analyze task, you may need to set that. –  Feb 07 '11 at 09:12
  • Strange 'ignoreNonCompile' doesn't default to true. – Leif Gruenwoldt Sep 09 '13 at 18:32
  • I'm wondering how analyze is done for the runtime scope. The docs only say: "anything that doesn't get into bytecode isn't detected. This is the case, for example, of constants, annotations with source retention policy, or javadoc links." But it's still interesting how it works for runtime at all. – Ruslan Sep 20 '17 at 15:05
0

Have you tried setting the scope of slf4j-log4j12 and log4j to runtime?
See maven dependency scope

crowne
  • 8,456
  • 3
  • 35
  • 50