简体   繁体   English

如何告诉maven-dependency-plugin工件中使用了工件?

[英]How to tell maven-dependency-plugin that the artifact is used in the project?

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. 换句话说,模块api使用slf4j进行日志记录。 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. 模块foo添加了slf4j-log4j12log4j以实现日志记录。 Pretty simple. 很简单。

Now I'm running maven-dependency-plugin:analyze-only and this is what it says for module foo : 现在我正在运行maven-dependency-plugin:analyze-only ,这就是它对模块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. 这意味着插件不理解foo确实需要这些依赖项。 How can I solve the problem? 我该如何解决这个问题?

What happens if you give those dependencies a runtime scope instead of compile ? 如果您将这些依赖项赋予runtime作用域而不是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. 但是在运行时只需要slf4-log4j和log4j JAR文件。

Edit: You may need to set the ignoreNonCompile option: 编辑:您可能需要设置ignoreNonCompile选项:

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

Have you tried setting the scope of slf4j-log4j12 and log4j to runtime? 您是否尝试将slf4j-log4j12log4j的范围设置为运行时?
See maven dependency scope 请参阅maven依赖范围

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM