本文介绍了如何告诉Maven-dependency-plugin项目中使用了工件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的多模块项目的结构:

This is a structure of my multi-module project:

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

换句话说,模块api使用slf4j进行日志记录.它不知道日志记录工具的实现是什么.模块foo添加了slf4j-log4j12log4j以便实现日志记录.很简单.

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.

现在我正在运行maven-dependency-plugin:analyze-only,这就是它对模块foo的说明:

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

意味着该插件不了解foo确实需要这些依赖项.我该如何解决这个问题?

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

推荐答案

如果为这些依赖项提供runtime范围而不是compile会发生什么?

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

如果您已将它们定义为编译时依赖项,那么我认为依赖项插件会认为它们在真正不需要时才需要进行编译.但是在运行时只需要slf4-log4j和log4j JAR文件.

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.

编辑:您可能需要设置ignoreNonCompile选项:

You may need to set the ignoreNonCompile option:

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

这篇关于如何告诉Maven-dependency-plugin项目中使用了工件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 18:28